FHIR © HL7.org  |  Server Home  |  FHIR Server FHIR Server 3.7.16  |  FHIR Version n/a  User: [n/a]

Resource StructureMap/FHIR Server from package ch.fhir.ig.cda-fhir-maps#0.3.0 (328 ms)

Package ch.fhir.ig.cda-fhir-maps
Type StructureMap
Id Id
FHIR Version R4
Source http://fhir.ch/ig/cda-fhir-maps/http://fhir.ch/ig/cda-fhir-maps/StructureMap-BundleToCdaChEmed.html
Url http://fhir.ch/ig/cda-fhir-maps/StructureMap/BundleToCdaChEmed
Version 0.3.0
Status draft
Date 2022-02-11T11:14:39+01:00
Name BundleToCdaChEmed
Experimental False
Realm ch
Authority hl7
Description Medication Entries 2020-11-11 Michaela Ziegler, copyright ahdis ag, Apache License CDA-CH-EMED: https://art-decor.org/art-decor/decor-project--cdachemed- FHIR CH-EMED: http://fhir.ch/ig/ch-emed/index.html
Copyright CC-BY-SA-4.0

Resources that use this resource

No resources found


Resources that this resource uses

No resources found



Narrative

Note: links and images are rebased to the (stated) source

map "http://fhir.ch/ig/cda-fhir-maps/StructureMap/BundleToCdaChEmed" = "BundleToCdaChEmed"


// Medication Entries
// 2020-11-11 Michaela Ziegler, copyright ahdis ag, Apache License
// CDA-CH-EMED:  https://art-decor.org/art-decor/decor-project--cdachemed-
// FHIR CH-EMED: http://fhir.ch/ig/ch-emed/index.html

uses "http://hl7.org/fhir/cda/StructureDefinition/ClinicalDocument" alias ClinicalDocument as target
uses "http://hl7.org/fhir/cda/StructureDefinition/AssignedAuthor" alias AssignedAuthor as target
uses "http://hl7.org/fhir/cda/StructureDefinition/AssignedEntity" alias AssignedEntity as target
uses "http://hl7.org/fhir/cda/StructureDefinition/Author" alias Author as target
uses "http://hl7.org/fhir/cda/StructureDefinition/CustodianOrganization" alias CustodianOrganization as target
uses "http://hl7.org/fhir/cda/StructureDefinition/IVL_TS" alias IVL_TS as target
uses "http://hl7.org/fhir/cda/StructureDefinition/EIVL_TS" alias EIVL_TS as target
uses "http://hl7.org/fhir/cda/StructureDefinition/PatientRole" alias PatientRole as target
uses "http://hl7.org/fhir/cda/StructureDefinition/RecordTarget" alias RecordTarget as target
uses "http://hl7.org/fhir/cda/StructureDefinition/Section" alias Section as target
uses "http://hl7.org/fhir/cda/StructureDefinition/SubstanceAdministration" alias SubstanceAdministration as target
uses "http://hl7.org/fhir/cda/StructureDefinition/SXPR_TS" alias SXPR_TS as target
uses "http://hl7.org/fhir/cda/StructureDefinition/Supply" alias Supply as target
uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias Bundle as source
uses "http://hl7.org/fhir/StructureDefinition/Composition" alias Composition as source
uses "http://hl7.org/fhir/StructureDefinition/Patient" alias Patient as source
uses "http://hl7.org/fhir/StructureDefinition/Practitioner" alias Practitioner as source
uses "http://hl7.org/fhir/StructureDefinition/Organization" alias Organization as source
uses "http://hl7.org/fhir/StructureDefinition/MedicationStatement" alias MedicationStatement as source
uses "http://hl7.org/fhir/StructureDefinition/Dosage" alias Dosage as source

imports "http://fhir.ch/ig/cda-fhir-maps/StructureMap/FhirToCdaTypes"
imports "http://fhir.ch/ig/cda-fhir-maps/StructureMap/BundleToCda"
imports "http://fhir.ch/ig/cda-fhir-maps/StructureMap/BundleToCdaCh"

// source: Annotation note (e.g. http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationstatement.html)
// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.4.2
group AnnotationComment(source note : Annotation, target act : Act) {
  note -> act.classCode = 'ACT' "ACT";
  note -> act.moodCode = 'EVN' "EVN";
  note ->  act.templateId as templateId,  templateId.root = '2.16.756.5.30.1.1.10.4.2' "templateId";
  note ->  act.templateId as templateId,  templateId.root = '2.16.840.1.113883.10.20.1.40' "templateId";
  note ->  act.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.2' "templateId";
  note ->  act.code as code,  code.code = '48767-8',  code.codeSystem = '2.16.840.1.113883.6.1',  code.displayName = 'Annotation comment',  code.codeSystemName = 'LOINC' "code";
  note.text as noteText -> act.text as text then {
    noteText -> text.data = noteText "text";
    note.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' then {
      extension.valueUrl as valueUrl ->  text.reference as reference,  reference.value = valueUrl "reference";
    } "id";
    note where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) ->  text.reference as reference,  reference.value = '#refpdf' "reference";
  };
  note ->  act.statusCode as code,  code.code = 'completed' "statusCode";
}

// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationstatement.html
// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.4.33&effectiveDate=2019-12-11T11:34:24&language=en-US
group ManufacturedMaterialEntryContentModuleStatement(source bundle : Bundle, source medicationStatement : MedicationStatement, source medication : Medication, target manufacturedMaterial : ManufacturedMaterial) {
  medication -> manufacturedMaterial.classCode = 'MMAT' "MMAT";
  medication -> manufacturedMaterial.determinerCode = 'KIND' "KIND";
  medication ->  manufacturedMaterial.templateId as templateId,  templateId.root = '2.16.756.5.30.1.1.10.4.33' "CH-PHARM-ManufacturedMaterialContentModule";
  medication ->  manufacturedMaterial.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.1' "templateId";
  medication.code as code then {
    code.text as text ->  manufacturedMaterial.name as name,  name.other = text "brandname";
  } "name";
  medication.code as code then {
    // #mtpc.no.brandedmedication
    code.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' -> manufacturedMaterial.code as code then {
      extension.valueUrl as valueUrl ->  code.originalText as text,  text.reference as reference,  reference.value = valueUrl "reference";
    } "id";
    code where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) ->  manufacturedMaterial.code as code,  code.originalText as text,  text.reference as reference,  reference.value = '#refpdf' "reference";
    code.coding as coding -> manufacturedMaterial.code as ce then CodingCE(coding, ce) "code";
    code where coding.exists() = false ->  manufacturedMaterial.code as ce,  ce.nullFlavor = 'NA' "nullFlavor";
  };
  medication.form as form then {
    form.coding as coding -> manufacturedMaterial.formCode as formCode then CodingCE(coding, formCode) "formCode";
  };
  medication.code as code ->  manufacturedMaterial.asContent as asContent,  asContent.classCode = 'CONT',  asContent.containerPackagedMedicine as containerPackagedMedicine then {
    code -> containerPackagedMedicine.classCode = 'CONT' "CONT";
    code -> containerPackagedMedicine.determinerCode = 'INSTANCE' "INSTANCE";
    code.coding as coding -> containerPackagedMedicine.code as ce then CodingCE(coding, ce) "pharm-code";
    code.text as text ->  containerPackagedMedicine.name as name,  name.other = text "pharm-name";
    medication.form as form then {
      form.coding as coding -> containerPackagedMedicine.formCode as formCode then CodingCE(coding, formCode) "pharm-formCode";
    };
    // Package size
    medication.amount as amount then {
      amount.numerator as numerator -> containerPackagedMedicine.capacityQuantity as capacityQuantity then {
        numerator.value as value -> capacityQuantity.value = value;
        numerator.code as unit -> capacityQuantity.unit = unit "unit";
      };
    };
  };
  medication.ingredient as ingredient ->  manufacturedMaterial.ingredient as ingredient,  ingredient.classCode = 'ACTI' then {
    ingredient.itemCodeableConcept as itemCodeableConcept -> ingredient.ingredient as pharmsubstance then {
      itemCodeableConcept -> pharmsubstance.classCode = 'MMAT' "MMAT";
      itemCodeableConcept -> pharmsubstance.determinerCode = 'KIND' "KIND";
      itemCodeableConcept.text as text ->  pharmsubstance.name as name,  name.other = text "name";
      itemCodeableConcept.coding as coding then {
        coding -> pharmsubstance.code as ce then CodingCE(coding, ce) "formCode";
      };
    } "PharmSubstance";
    ingredient.strength as strength -> ingredient.quantity as quantity then RatioRTOPQPQ(strength, quantity);
  };
}

// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationstatement.html
// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.4.34&effectiveDate=2019-12-11T11:31:52&language=en-US
group MedicationTreatmentPlanItemEntryContentModule(source bundle : Bundle, source medicationStatement : MedicationStatement, target substanceAdministration : SubstanceAdministration) {
  medicationStatement -> substanceAdministration.classCode = 'SBADM' "SBADM";
  medicationStatement -> substanceAdministration.moodCode = 'INT' "INT";
  medicationStatement ->  substanceAdministration.templateId as templateId,  templateId.root = '2.16.756.5.30.1.1.10.4.34' "CH-PHARM-MedicationTreatmentPlanItemEntryContentModule";
  medicationStatement ->  substanceAdministration.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.7' "IHE-PHARM-MTP";
  medicationStatement ->  substanceAdministration.templateId as templateId,  templateId.root = '2.16.840.1.113883.10.20.1.24' "CCD";
  medicationStatement ->  substanceAdministration.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7' "PCC-MedicationEntryContentModule";
  medicationStatement.identifier as identifier -> substanceAdministration.id as id then IdentifierII(identifier, id) "id";
  medicationStatement.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' ->  substanceAdministration.text as text,  text.reference as reference then {
    extension.valueUrl as valueUrl -> reference.value = valueUrl;
  } "narrativeLink";
  medicationStatement where extension.where(url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists().not() ->  substanceAdministration.text as text,  text.reference as reference then {
    medicationStatement -> reference.value = '#refpdf' "referencetopdf";
  } "cat1narrativelink";
  medicationStatement ->  substanceAdministration.statusCode as statusCode,  statusCode.code = 'completed' "code";
  medicationStatement.contained as medication where ('#' + $this.id) in %medicationStatement.medicationReference.reference ->  substanceAdministration.consumable as consumable,  consumable.manufacturedProduct as manufacturedProduct,  manufacturedProduct.classCode = 'MANU' then {
    medication ->  manufacturedProduct.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.2' "MP-TemplateId";
    medication ->  manufacturedProduct.templateId as templateId,  templateId.root = '2.16.840.1.113883.10.20.1.53' "MP-TemplateId";
    medication -> manufacturedProduct.manufacturedMaterial as manufacturedMaterial then ManufacturedMaterialEntryContentModuleStatement(bundle, medicationStatement, medication, manufacturedMaterial) "manufacturedMaterial";
  };
  // TODO: AUTHOR1 Medication Treatment Plan Author
  medicationStatement where dosage.count() = 1 then {
    medicationStatement.dosage as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-nonstructured') ->  substanceAdministration.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.1' "normalDose";
  } "onylonedosage";
  // dosage for normal dosing, as no sequences are present there
  medicationStatement.dosage as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-normal') then DosageInstructionsStartStopFrequencySubstanceAdministration(dosage, substanceAdministration) "DosageSubstanceAdministration";
  // dosage for split dosing (with sequences): effectiveTime (start/stop) & routeCode
  medicationStatement.dosage first as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split') -> substanceAdministration.entryRelationship as entryRelationship then DosageInstructionsEntryStartStopRoute(dosage, substanceAdministration, entryRelationship) "DosageSubstanceAdministration";
  // dosage for split dosing (with sequences): sequence number, effectiveTime (when), dose quantity, consumable
  medicationStatement.dosage as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split') ->  substanceAdministration.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'COMP' then DosageInstructionsEntryDosageChangeSubstanceAdministration(dosage, substanceAdministration, entryRelationship) "DosageSubstanceAdministration";
  medicationStatement.reasonCode as reasonCode ->  substanceAdministration.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'RSON',  entryRelationship.observation as observation then TreatmentReasonEntryContentModule(reasonCode, observation) "TreatmentReasonEntryContentModule";
  medicationStatement.extension as extension where url = 'http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-ext-treatmentplan' ->  substanceAdministration.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'REFR',  entryRelationship.substanceAdministration as substanceAdministration then MTPReferenceEntryContentModule(extension, substanceAdministration) "MTP-Reference";
  // https://github.com/ehealthsuisse/ch-emed/issues/56
  medicationStatement ->  substanceAdministration.repeatNumber as repeatNumber,  repeatNumber.nullFlavor = 'NI' "repeatNumberDefault";
  // TODO: Patient Medication Instructions Contains 1.3.6.1.4.1.19376.1.5.3.1.4.3 IHE Patient Medication Instructions (DYNAMIC)
  medicationStatement.dosage as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-nonstructured') ->  substanceAdministration.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'COMP',  entryRelationship.substanceAdministration as substanceAdministration then DosageInstructionsNonStructuredEntryContentModule(dosage, substanceAdministration) "DosageInstructionsNonStructuredEntryContentModule";
  medicationStatement.note as note ->  substanceAdministration.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'COMP',  entryRelationship.act as act then AnnotationComment(note, act) "AnnotationComment";
  medicationStatement.extension as extension where $this.url = 'http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-ext-substitution' ->  substanceAdministration.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'COMP',  entryRelationship.act as act then SubstitutionStatement(extension, act) "Substitution";
}

// TODO: Tapered Dose
// medicationStatement -> substanceAdministration.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.8' "taperedDose";
// source: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-normal
// target: https://art-decor.org/art-decor/decor-templates--ch-pharm-?id=2.16.756.5.30.1.1.10.4.35
// dosage for normal dosing (without sequences) (Statement, Prescription)
group DosageInstructionsStartStopFrequencySubstanceAdministration(source dosage : Dosage, target substanceAdministration : SubstanceAdministration) {
  dosage ->  substanceAdministration.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.1' "normalDose";
  dosage as dosage -> substanceAdministration as substanceAdministration then EffectiveTimeStartEnd(dosage, substanceAdministration) "effectiveTimeStartEnd";
  dosage as dosage -> substanceAdministration as substanceAdministration then EffectiveTimeWhenNormal(dosage, substanceAdministration) "effectiveTimeWhen";
  dosage.route as route -> substanceAdministration.routeCode as routeCode then CodeableConceptCE(route, routeCode);
  dosage as dosage -> substanceAdministration as substanceAdministration then DoseQuantity(dosage, substanceAdministration) "doseQuantity";
}

// source: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split
// target: https://art-decor.org/art-decor/decor-templates--ch-pharm-?id=2.16.756.5.30.1.1.10.4.36
// dosage for split dosing: effectiveTime (start/stop) & routeCode (Statement, Prescription)
group DosageInstructionsEntryStartStopRoute(source dosage : Dosage, target substanceAdministration : substanceAdministration, target entry : entryRelationship) {
  // if the FHIR doucment has no dosage templateId -> create templateId for split dose
  dosage ->  substanceAdministration.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.9' "splitDose";
  dosage as dosage -> substanceAdministration as substanceAdministration then EffectiveTimeStartEnd(dosage, substanceAdministration) "effectiveTimeStartEnd";
  dosage.route as route -> substanceAdministration.routeCode as routeCode then CodeableConceptCE(route, routeCode);
}

// source: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split
// target: https://art-decor.org/art-decor/decor-templates--ch-pharm-?id=2.16.756.5.30.1.1.10.4.36
// dosage for split dosing: sequence number, effectiveTime (when), dose quantity, consumable (Statement, Prescription)
group DosageInstructionsEntryDosageChangeSubstanceAdministration(source dosage : Dosage, target substanceAdministration : substanceAdministration, target entry : entryRelationship) {
  dosage.sequence as sequence ->  entry.sequenceNumber as sequenceNumber,  sequenceNumber.value = sequence;
  dosage ->  entry.substanceAdministration as substanceAdministration,  substanceAdministration.classCode = 'SBADM',  substanceAdministration.moodCode = 'INT' then {
    dosage as dosage -> substanceAdministration as substanceAdministration then EffectiveTimeWhenSplit(dosage, substanceAdministration) "effectiveTimeWhen";
    dosage as dosage -> substanceAdministration as substanceAdministration then DoseQuantity(dosage, substanceAdministration) "doseQuantity";
    dosage as dosage ->  substanceAdministration as substanceAdministration,  substanceAdministration.consumable as consumable,  consumable.manufacturedProduct as manufacturedProduct,  manufacturedProduct.manufacturedMaterial as manufacturedMaterial,  manufacturedMaterial.nullFlavor = 'NA' "consumable";
  } "dosage";
}

// effective time low and high for dosage (Statement, Prescription)
group EffectiveTimeStartEnd(source dosage : Dosage, target substanceAdministration : SubstanceAdministration) {
  dosage.timing as timing then {
    timing.repeat as repeat then {
      repeat.bounds : Period as bounds -> substanceAdministration.effectiveTime = create('IVL_TS') as effectiveTime then {
        bounds.start as start -> effectiveTime.low as low then DateTS(start, low) "low";
        bounds where start.exists().not() ->  effectiveTime.low as low,  low.nullFlavor = 'UNK' "NullFlavorLow";
        bounds.end as end -> effectiveTime.high as high then DateTS(end, high) "high";
        bounds where end.exists().not() ->  effectiveTime.high as high,  high.nullFlavor = 'UNK' "NullFlavorhigh";
      };
    };
  };
}

// dose quantity for dosage (application schema) (Statement)
group DoseQuantity(source dosage : Dosage, target substanceAdministration : SubstanceAdministration) {
  dosage.doseAndRate as doseAndRate -> substanceAdministration.doseQuantity as doseQuantity then {
    doseAndRate.dose : Quantity as quantity then {
      quantity.value as value -> doseQuantity.value = value;
      quantity.code as code -> doseQuantity.unit = code;
    } "quantity";
  } "doseQuantity";
}

// source: reasonCode Coding (e.g. http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-medicationstatement)
// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.4.41
// Treatment Reason (Statement, Prescription)
group TreatmentReasonEntryContentModule(source reasonCode : Coding, target observation : Observation) {
  reasonCode -> observation.classCode = 'OBS' "OBS";
  reasonCode -> observation.moodCode = 'EVN' "EVN";
  reasonCode ->  observation.templateId as templateId,  templateId.root = '2.16.756.5.30.1.1.10.4.41' "TreatmentReasonEntryContentModule";
  reasonCode ->  observation.code as code,  code.code = '75326-9',  code.codeSystem = '2.16.840.1.113883.6.1',  code.displayName = 'Problem',  code.codeSystemName = 'LOINC' "code";
  reasonCode.text as reasonText -> observation.text as text then {
    reasonText -> text.data = reasonText "text";
    reasonCode.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' then {
      extension.valueUrl as valueUrl ->  text.reference as reference,  reference.value = valueUrl "reference";
    } "id";
    reasonCode where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) ->  text.reference as reference,  reference.value = '#refpdf' "reference";
  };
  reasonCode ->  observation.statusCode as code,  code.code = 'completed' "statusCode";
}

// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-ext-treatmentplan.html
// target: https://art-decor.org/art-decor/decor-templates--ch-pharm-?section=templates&id=2.16.756.5.30.1.1.10.4.45&effectiveDate=2017-01-10T15:34:25&language=en-US
group MTPReferenceEntryContentModule(source ext : Extension, target substanceAdministration : SubstanceAdministration) {
  ext -> substanceAdministration.classCode = 'SBADM' "SBADM";
  ext -> substanceAdministration.moodCode = 'INT' "INT";
  ext ->  substanceAdministration.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.10' "referenceTo-MTP-PlanItemGeneralSpecificationTemplateId";
  ext ->  substanceAdministration.templateId as templateId,  templateId.root = '2.16.756.5.30.1.1.10.4.45' "CH-PHARM-templateId";
  ext.extension as extension where $this.url = 'id' then {
    extension.valueIdentifier as valueIdentifier -> substanceAdministration.id as id then IdentifierII(valueIdentifier, id) "id";
  } "id";
  ext ->  substanceAdministration.code as code,  code.code = 'MTPItem',  code.codeSystem = '1.3.6.1.4.1.19376.1.9.2.2',  code.displayName = 'Medication Treatment Plan Item',  code.codeSystemName = 'IHE Pharmacy Item Type List' "code";
  ext ->  substanceAdministration.consumable as consumable,  consumable.manufacturedProduct as manufacturedProduct,  manufacturedProduct.manufacturedMaterial as manufacturedMaterial,  manufacturedMaterial.nullFlavor = 'NA' "consumable";
  ext.extension as extension where $this.url = 'externalDocumentId' then {
    extension.valueIdentifier as valueIdentifier ->  substanceAdministration.reference as reference,  reference.typeCode = 'XCRPT',  reference.externalDocument as externalDocument,  externalDocument.id as id then IdentifierII(valueIdentifier, id) "id";
  } "externalDocumentId";
}

// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-dosage-nonstructured.html
// target: https://art-decor.org/art-decor/decor-templates--ch-pharm-?section=templates&id=2.16.756.5.30.1.1.10.4.52
// Dosage Instruction (Statement, Prescription)
group DosageInstructionsNonStructuredEntryContentModule(source dosage : Dosage, target substanceAdministration : SubstanceAdministration) {
  dosage -> substanceAdministration.classCode = 'SBADM' "SBADM";
  dosage -> substanceAdministration.moodCode = 'INT' "INT";
  dosage ->  substanceAdministration.templateId as templateId,  templateId.root = '2.16.756.5.30.1.1.10.4.52' "templateId";
  dosage.text as noteText -> substanceAdministration.text as text then {
    noteText -> text.data = noteText "text";
    dosage.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' then {
      extension.valueUrl as valueUrl ->  text.reference as reference,  reference.value = valueUrl "reference";
    } "id";
    dosage where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) ->  text.reference as reference,  reference.value = '#refpdf' "reference";
  };
  dosage ->  substanceAdministration.consumable as consumable,  consumable.manufacturedProduct as manufacturedProduct,  manufacturedProduct.manufacturedMaterial as manufacturedMaterial,  manufacturedMaterial.nullFlavor = 'NA' "consumable";
}

// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationdispense.html
// target: Substitution act Contains 1.3.6.1.4.1.19376.1.9.1.3.9.2 IHE Substitution Act Content Module
// Substitution (Dispense)
group SubstitutionDispense(source substitution : Substitution, target act : Act) {
  substitution -> act.classCode = 'ACT' "ACT";
  substitution -> act.moodCode = 'EVN' "EVN";
  substitution ->  act.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.9.2' "templateId";
  substitution.type as type -> act.code as code then CodeableConceptCE(type, code) "substitution";
  substitution ->  act.statusCode as statusCode,  statusCode.code = 'completed' "statusCode";
}

// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationdispense.html
// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.4.33&effectiveDate=2019-12-11T11:34:24&language=en-US
group ManufacturedMaterialEntryContentModuleDispense(source bundle : Bundle, source medicationDispense : MedicationDispense, source medication : Medication, target manufacturedMaterial : ManufacturedMaterial) {
  medication -> manufacturedMaterial.classCode = 'MMAT' "MMAT";
  medication -> manufacturedMaterial.determinerCode = 'KIND' "KIND";
  medication ->  manufacturedMaterial.templateId as templateId,  templateId.root = '2.16.756.5.30.1.1.10.4.33' "CH-PHARM-ManufacturedMaterialContentModule";
  medication ->  manufacturedMaterial.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.1' "templateId";
  medication.code as code then {
    code.text as text ->  manufacturedMaterial.name as name,  name.other = text "brandname";
  } "name";
  medication.code as code then {
    // #dis.no.brandedmedication
    code.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' -> manufacturedMaterial.code as code then {
      extension.valueUrl as valueUrl ->  code.originalText as text,  text.reference as reference,  reference.value = valueUrl "reference";
    } "id";
    code where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) ->  manufacturedMaterial.code as code,  code.originalText as text,  text.reference as reference,  reference.value = '#refpdf' "reference";
    code.coding as coding -> manufacturedMaterial.code as ce then CodingCE(coding, ce) "code";
  };
  medication.form as form then {
    form.coding as coding -> manufacturedMaterial.formCode as formCode then CodingCE(coding, formCode) "formCode";
  };
  medication.code as code ->  manufacturedMaterial.asContent as asContent,  asContent.classCode = 'CONT',  asContent.containerPackagedMedicine as containerPackagedMedicine then {
    code -> containerPackagedMedicine.classCode = 'CONT' "CONT";
    code -> containerPackagedMedicine.determinerCode = 'INSTANCE' "INSTANCE";
    code.coding as coding -> containerPackagedMedicine.code as ce then CodingCE(coding, ce) "pharm-code";
    code.text as text ->  containerPackagedMedicine.name as name,  name.other = text "pharm-name";
    medication.form as form then {
      form.coding as coding -> containerPackagedMedicine.formCode as formCode then CodingCE(coding, formCode) "pharm-formCode";
    };
    // Package size
    medication.amount as amount then {
      amount.numerator as numerator -> containerPackagedMedicine.capacityQuantity as capacityQuantity then {
        numerator.value as value -> capacityQuantity.value = value;
        numerator.code as unit -> capacityQuantity.unit = unit "unit";
      };
    };
  };
  medication.ingredient as ingredient ->  manufacturedMaterial.ingredient as ingredient,  ingredient.classCode = 'ACTI' then {
    ingredient.itemCodeableConcept as itemCodeableConcept -> ingredient.ingredient as pharmsubstance then {
      itemCodeableConcept -> pharmsubstance.classCode = 'MMAT' "MMAT";
      itemCodeableConcept -> pharmsubstance.determinerCode = 'KIND' "KIND";
      itemCodeableConcept.text as text ->  pharmsubstance.name as name,  name.other = text "name";
      itemCodeableConcept.coding as coding then {
        coding -> pharmsubstance.code as ce then CodingCE(coding, ce) "formCode";
      };
    } "PharmSubstance";
    ingredient.strength as strength -> ingredient.quantity as quantity then RatioRTOPQPQ(strength, quantity);
  };
}

// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationdispense.html
// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.4.42
group DispenseItemEntryContentModule(source bundle : Bundle, source medicationDispense : MedicationDispense, target supply : Supply) {
  medicationDispense -> supply.classCode = 'SPLY' "SPLY";
  medicationDispense -> supply.moodCode = 'EVN' "EVN";
  medicationDispense ->  supply.templateId as templateId,  templateId.root = '2.16.756.5.30.1.1.10.4.42' "CH-PHARM-DispenseItemEntryContentModule";
  medicationDispense ->  supply.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.4' "IHE-PHARM-DIS";
  medicationDispense ->  supply.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.3' "supplyEntry";
  medicationDispense ->  supply.templateId as templateId,  templateId.root = '2.16.840.1.113883.10.20.1.34' "CCD";
  medicationDispense.identifier as identifier -> supply.id as id then IdentifierII(identifier, id) "id";
  medicationDispense.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' ->  supply.text as text,  text.reference as reference then {
    extension.valueUrl as valueUrl -> reference.value = valueUrl;
  } "narrativeLink";
  medicationDispense where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) ->  supply.text as text,  text.reference as reference,  text.reference as reference,  reference.value = '#refpdf' "reference";
  medicationDispense.contained as medication where ('#' + $this.id) in %medicationDispense.medicationReference.reference ->  supply.product as product,  product.manufacturedProduct as manufacturedProduct,  manufacturedProduct.classCode = 'MANU' then {
    medication ->  manufacturedProduct.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.2' "MP-TemplateId";
    medication ->  manufacturedProduct.templateId as templateId,  templateId.root = '2.16.840.1.113883.10.20.1.53' "MP-TemplateId";
    medication -> manufacturedProduct.manufacturedMaterial as manufacturedMaterial then ManufacturedMaterialEntryContentModuleDispense(bundle, medicationDispense, medication, manufacturedMaterial) "manufacturedMaterial";
  };
  // TODO: AUTHOR1 Medication Treatment Plan Author
  medicationDispense.extension as extension where url = 'http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-ext-treatmentplan' ->  supply.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'REFR',  entryRelationship.substanceAdministration as substanceAdministration then MTPReferenceEntryContentModule(extension, substanceAdministration) "MTP-Reference";
  // #24 missing template it if ch-emed-dosage-nonstructured
  medicationDispense where dosageInstruction.count() = 1 then {
    medicationDispense.dosageInstruction as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-nonstructured') ->  substanceAdministration.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.1' "normalDose";
  } "onylonedosage";
  // dosage for normal dosing, as no sequences are present there
  medicationDispense.dosageInstruction as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-normal') then DosageInstructionsStartStopFrequencySupply(dosage, supply) "DosageSubstanceAdministration";
  // dosage for split dosing, as sequences are present there
  medicationDispense -> supply.entryRelationship as entryRelationship then {
    medicationDispense -> entryRelationship.substanceAdministration as substanceAdministration then {
      // split dosing (with sequences): effectiveTime (start/stop) & routeCode & consumable
      medicationDispense.dosageInstruction first as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split') -> substanceAdministration then DosageInstructionsEntryStartStopRouteConsumable(dosage, entryRelationship, substanceAdministration) "DosageSubstanceAdministration";
      // split dosing (with sequences): sequence number, effectiveTime (when), dose quantity, consumable
      medicationDispense.dosageInstruction as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split') ->  substanceAdministration.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'COMP' then DosageInstructionsEntryDosageChangeEntryRelationship(dosage, entryRelationship) "DosageSubstanceAdministration";
    } "substanceAdministration";
  } "entryRelationship";
  // TODO: Precondition Criterion
  medicationDispense.dosageInstruction as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-nonstructured') ->  supply.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'COMP',  entryRelationship.substanceAdministration as substanceAdministration then DosageInstructionsNonStructuredEntryContentModule(dosage, substanceAdministration) "DosageInstructionsNonStructuredEntryContentModule";
  // Number of packages
  medicationDispense.quantity as quantity -> supply.quantity as supplyQuantity then {
    quantity.value as value -> supplyQuantity.value = value;
  };
  medicationDispense.note as note ->  supply.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'COMP',  entryRelationship.act as act then AnnotationComment(note, act) "AnnotationComment";
  medicationDispense.substitution as substitution ->  supply.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'COMP',  entryRelationship.act as act then SubstitutionDispense(substitution, act) "Substitution";
}

// source: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-normal
// target: https://art-decor.org/art-decor/decor-templates--ch-pharm-?id=2.16.756.5.30.1.1.10.4.35
// dosage for normal dosing (without sequences) (Dispense)
group DosageInstructionsStartStopFrequencySupply(source dosage : Dosage, target supply : Supply) {
  dosage -> supply.entryRelationship as entryRelationship then {
    dosage -> entryRelationship.typeCode = 'COMP' "COMP";
    dosage -> entryRelationship.substanceAdministration as substanceAdministration then {
      dosage -> substanceAdministration.classCode = 'SBADM' "SBADM";
      dosage -> substanceAdministration.moodCode = 'INT' "INT";
      dosage ->  substanceAdministration.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.6' "templateId";
      dosage ->  substanceAdministration.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.1' "normalDose";
      dosage -> substanceAdministration as substanceAdministration then EffectiveTimeStartEnd(dosage, substanceAdministration) "effectiveTimeStartEnd";
      dosage -> substanceAdministration as substanceAdministration then EffectiveTimeWhenNormal(dosage, substanceAdministration) "effectiveTimeWhen";
      dosage.route as route -> substanceAdministration.routeCode as routeCode then CodeableConceptCE(route, routeCode);
      dosage -> substanceAdministration as substanceAdministration then DoseQuantity(dosage, substanceAdministration) "doseQuantity";
      dosage ->  substanceAdministration as substanceAdministration,  substanceAdministration.consumable as consumable,  consumable.manufacturedProduct as manufacturedProduct,  manufacturedProduct.manufacturedMaterial as manufacturedMaterial,  manufacturedMaterial.nullFlavor = 'NA' "consumable";
    } "substanceAdministration";
  } "entryRelationship";
}

// source: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split
// target: https://art-decor.org/art-decor/decor-templates--ch-pharm-?id=2.16.756.5.30.1.1.10.4.36
// dosage for split dosing: effectiveTime (start/stop) & routeCode & consumable (Dispense)
group DosageInstructionsEntryStartStopRouteConsumable(source dosage : Dosage, target entryRelationship : entryRelationship, target substanceAdministration : SubstanceAdministration) {
  dosage -> entryRelationship.typeCode = 'COMP' "COMP";
  dosage -> substanceAdministration.classCode = 'SBADM' "SBADM";
  dosage -> substanceAdministration.moodCode = 'INT' "INT";
  dosage ->  substanceAdministration.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.6' "templateId";
  dosage ->  substanceAdministration.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.9' "splitDose";
  dosage -> substanceAdministration as substanceAdministration then EffectiveTimeStartEnd(dosage, substanceAdministration) "effectiveTimeStartEnd";
  dosage.route as route -> substanceAdministration.routeCode as routeCode then CodeableConceptCE(route, routeCode);
  dosage ->  substanceAdministration.consumable as consumable,  consumable.manufacturedProduct as manufacturedProduct,  manufacturedProduct.manufacturedMaterial as manufacturedMaterial,  manufacturedMaterial.nullFlavor = 'NA' "consumable";
}

// source: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split
// target: https://art-decor.org/art-decor/decor-templates--ch-pharm-?id=2.16.756.5.30.1.1.10.4.36
// dosage for split dosing: sequence number, effectiveTime (when), dose quantity, consumable (Dispense)
group DosageInstructionsEntryDosageChangeEntryRelationship(source dosage : Dosage, target entryRelationship : entryRelationship) {
  dosage.sequence as sequence ->  entryRelationship.sequenceNumber as sequenceNumber,  sequenceNumber.value = sequence;
  dosage ->  entryRelationship.substanceAdministration as substanceAdministration,  substanceAdministration.classCode = 'SBADM',  substanceAdministration.moodCode = 'INT' then {
    dosage as dosage -> substanceAdministration then EffectiveTimeWhenSplit(dosage, substanceAdministration) "effectiveTimeWhen";
    dosage as dosage -> substanceAdministration then DoseQuantity(dosage, substanceAdministration) "doseQuantity";
    dosage as dosage ->  substanceAdministration.consumable as consumable,  consumable.manufacturedProduct as manufacturedProduct,  manufacturedProduct.manufacturedMaterial as manufacturedMaterial,  manufacturedMaterial.nullFlavor = 'NA' "consumable";
  } "dosage";
}

// effective time when for normal dosage (Dispense, Statement, Prescription)
group EffectiveTimeWhenNormal(source dosage : Dosage, target substanceAdministration : SubstanceAdministration) {
  dosage.timing as timing then {
    timing.repeat as repeat then {
      repeat where $this.when.count() = 1 ->  substanceAdministration.effectiveTime = create('EIVL_TS') as effectiveTime,  effectiveTime.operator = 'A' then {
        repeat.when as when ->  effectiveTime.event as event,  event.code = when;
      } "when";
      repeat where $this.when.count() > 1 ->  substanceAdministration.effectiveTime = create('SXPR_TS') as effectiveTime,  effectiveTime.operator = 'A' then {
        repeat.when first as when -> effectiveTime.comp = create('EIVL_TS') as comp then {
          when ->  comp.event as event,  event.code = when "when";
        } "comp";
        repeat.when not_first as when ->  effectiveTime.comp = create('EIVL_TS') as comp,  comp.operator = 'I' then {
          when ->  comp.event as event,  event.code = when "when";
        } "compnotfirst";
      } "when";
    };
  };
}

// effective time when for split dosage (Dispense, Statement, Prescription)
group EffectiveTimeWhenSplit(source dosage : Dosage, target substanceAdministration : SubstanceAdministration) {
  dosage.timing as timing then {
    timing.repeat as repeat then {
      repeat where $this.when.count() = 1 -> substanceAdministration.effectiveTime = create('EIVL_TS') as effectiveTime then {
        repeat.when as when ->  effectiveTime.event as event,  event.code = when;
      } "when";
      repeat where $this.when.count() > 1 ->  substanceAdministration.effectiveTime = create('SXPR_TS') as effectiveTime,  effectiveTime.operator = 'A' then {
        repeat.when first as when -> effectiveTime.comp = create('EIVL_TS') as comp then {
          when ->  comp.event as event,  event.code = when "when";
        } "comp";
        repeat.when not_first as when ->  effectiveTime.comp = create('EIVL_TS') as comp,  comp.operator = 'I' then {
          when ->  comp.event as event,  event.code = when "when";
        } "compnotfirst";
      } "when";
    };
  };
}

// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationrequest.html
// target: Substitution permission Contains 1.3.6.1.4.1.19376.1.9.1.3.9.1 IHE Substitution Permission Content Module
group SubstitutionRequest(source substitution : Substitution, target act : Act) {
  substitution -> act.classCode = 'ACT' "ACT";
  substitution -> act.moodCode = 'DEF' "DEF";
  substitution ->  act.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.9.1' "templateId";
  substitution.allowedCodeableConcept as allowedCC -> act.code as code then CodeableConceptCE(allowedCC, code) "substitution";
  substitution ->  act.statusCode as statusCode,  statusCode.code = 'completed' "statusCode";
}

// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationrequest.html
// target: Substitution permission Contains 1.3.6.1.4.1.19376.1.9.1.3.9.1 IHE Substitution Permission Content Module
group SubstitutionStatement(source extension : Extension, target act : Act) {
  extension -> act.classCode = 'ACT' "ACT";
  extension -> act.moodCode = 'DEF' "DEF";
  extension ->  act.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.9.1' "templateId";
  extension.valueCodeableConcept as valueCC -> act.code as code then CodeableConceptCE(valueCC, code) "extension";
  extension ->  act.statusCode as statusCode,  statusCode.code = 'completed' "statusCode";
}

// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationrequest.html
// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?id=2.16.756.5.30.1.1.10.4.38
group PrescribedQuantity(source dispenseRequest : DispenseRequest, target supply : Supply) {
  dispenseRequest -> supply.classCode = 'SPLY' "SPLY";
  dispenseRequest -> supply.moodCode = 'RQO' "RQO";
  dispenseRequest ->  supply.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.8' "templateId";
  dispenseRequest ->  supply.independentInd as independentInd,  independentInd.value = 'false' "independentInd";
  // Number of packages
  dispenseRequest.quantity as quantity -> supply.quantity as quant then {
    quantity.value as value -> quant.value = value;
  };
}

// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationrequest.html
// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?id=2.16.756.5.30.1.1.10.4.38
group PrescribedQuantityUnit(source dispenseRequest : DispenseRequest, target supply : Supply) {
  dispenseRequest -> supply.classCode = 'SPLY' "SPLY";
  dispenseRequest -> supply.moodCode = 'RQO' "RQO";
  dispenseRequest ->  supply.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.8' "TemplateId";
  dispenseRequest ->  supply.independentInd as independentInd,  independentInd.value = 'false' "independentInd";
  // Number of packages
  dispenseRequest.quantity as quantity -> supply.quantity as quant then {
    quantity.value as value -> quant.value = value;
    quantity.unit as unit -> quant.unit = unit;
  };
}

// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationrequest.html
// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.4.33
group ManufacturedMaterialEntryContentModulePrescription(source bundle : Bundle, source medicationRequest : MedicationRequest, source medication : Medication, target manufacturedMaterial : ManufacturedMaterial, target substanceAdministration : SubstanceAdministration) {
  medication -> manufacturedMaterial.classCode = 'MMAT' "MMAT";
  medication -> manufacturedMaterial.determinerCode = 'KIND' "KIND";
  medication ->  manufacturedMaterial.templateId as templateId,  templateId.root = '2.16.756.5.30.1.1.10.4.33' "CH-PHARM-ManufacturedMaterialContentModule";
  medication ->  manufacturedMaterial.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.1' "templateId";
  medication.code as code then {
    code.text as text ->  manufacturedMaterial.name as name,  name.other = text "brandname";
  } "name";
  medication.code as code then {
    // #pre.no.brandedmedication
    code.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' -> manufacturedMaterial.code as code then {
      extension.valueUrl as valueUrl ->  code.originalText as text,  text.reference as reference,  reference.value = valueUrl "reference";
    } "id";
    code where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) ->  manufacturedMaterial.code as code,  code.originalText as text,  text.reference as reference,  reference.value = '#refpdf' "reference";
    code.coding as coding -> manufacturedMaterial.code as ce then CodingCE(coding, ce) "code";
  };
  medication.form as form then {
    form.coding as coding -> manufacturedMaterial.formCode as formCode then CodingCE(coding, formCode) "formCode";
  };
  medication.code as code ->  manufacturedMaterial.asContent as asContent,  asContent.classCode = 'CONT',  asContent.containerPackagedMedicine as containerPackagedMedicine then {
    code -> containerPackagedMedicine.classCode = 'CONT' "CONT";
    code -> containerPackagedMedicine.determinerCode = 'INSTANCE' "INSTANCE";
    code.coding as coding -> containerPackagedMedicine.code as ce then CodingCE(coding, ce) "pharm-code";
    code.text as text ->  containerPackagedMedicine.name as name,  name.other = text "pharm-name";
    medication.form as form then {
      form.coding as coding -> containerPackagedMedicine.formCode as formCode then CodingCE(coding, formCode) "pharm-formCode";
    };
    // Package size
    medication.amount as amount then {
      amount.numerator as numerator -> containerPackagedMedicine.capacityQuantity as capacityQuantity then {
        numerator.value as value -> capacityQuantity.value = value;
        numerator.code as unit -> capacityQuantity.unit = unit "unit";
      };
      // IHE-DIS: Case 1: If the product-element contains package information, the unit attribute is not be present
      medicationRequest.dispenseRequest as dispenseRequest ->  substanceAdministration.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'COMP',  entryRelationship.supply as supply then PrescribedQuantity(dispenseRequest, supply) "PrescribedQuantity";
    };
    // IHE-DIS: Case 2: If the product-element does not contain package information, the unit attribut is present and the value SHALL be out of the UCUM code system
    medication where $this.amount.exists() = false then {
      medicationRequest.dispenseRequest as dispenseRequest ->  substanceAdministration.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'COMP',  entryRelationship.supply as supply then PrescribedQuantityUnit(dispenseRequest, supply) "PrescribedQuantityUnit";
    } "noAmount";
  };
  medication.ingredient as ingredient ->  manufacturedMaterial.ingredient as ingredient,  ingredient.classCode = 'ACTI' then {
    ingredient.itemCodeableConcept as itemCodeableConcept -> ingredient.ingredient as pharmsubstance then {
      itemCodeableConcept -> pharmsubstance.classCode = 'MMAT' "MMAT";
      itemCodeableConcept -> pharmsubstance.determinerCode = 'KIND' "KIND";
      itemCodeableConcept.text as text ->  pharmsubstance.name as name,  name.other = text "name";
      itemCodeableConcept.coding as coding then {
        coding -> pharmsubstance.code as ce then CodingCE(coding, ce) "formCode";
      };
    } "PharmSubstance";
    ingredient.strength as strength -> ingredient.quantity as quantity then RatioRTOPQPQ(strength, quantity);
  };
}

// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationrequest.html
// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.4.43
group PrescriptionItemEntryContentModule(source bundle : Bundle, source medicationRequest : MedicationRequest, target substanceAdministration : SubstanceAdministration) {
  medicationRequest -> substanceAdministration.classCode = 'SBADM' "SBADM";
  medicationRequest -> substanceAdministration.moodCode = 'INT' "INT";
  medicationRequest ->  substanceAdministration.templateId as templateId,  templateId.root = '2.16.756.5.30.1.1.10.4.43' "CH-PHARM-PrescriptionItemEntryContentModule";
  medicationRequest ->  substanceAdministration.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.2' "PrescriptionItemEntryTemplateId";
  medicationRequest ->  substanceAdministration.templateId as templateId,  templateId.root = '2.16.840.1.113883.10.20.1.24' "CCD";
  medicationRequest ->  substanceAdministration.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7' "PCC-MedicationEntryContentModule";
  medicationRequest.identifier as identifier -> substanceAdministration.id as id then IdentifierII(identifier, id) "id";
  medicationRequest.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' ->  substanceAdministration.text as text,  text.reference as reference then {
    extension.valueUrl as valueUrl -> reference.value = valueUrl;
  } "narrativeLink";
  medicationRequest where extension.where(url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists().not() ->  substanceAdministration.text as text,  text.reference as reference then {
    medicationRequest -> reference.value = '#refpdf' "referencetopdf";
  } "cat1narrativelink";
  medicationRequest ->  substanceAdministration.statusCode as statusCode,  statusCode.code = 'completed' "code";
  medicationRequest.dispenseRequest as dispenseRequest -> substanceAdministration.repeatNumber as repeatNumber then {
    dispenseRequest.numberOfRepeatsAllowed as number -> repeatNumber.value = number "repeatNumber";
    dispenseRequest where numberOfRepeatsAllowed.exists() = false -> repeatNumber.nullFlavor = 'NI' "repeatNumberNull";
  };
  medicationRequest.contained as medication where ('#' + $this.id) in %medicationRequest.medicationReference.reference ->  substanceAdministration.consumable as consumable,  consumable.manufacturedProduct as manufacturedProduct,  manufacturedProduct.classCode = 'MANU' then {
    medication ->  manufacturedProduct.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.2' "MP-templateId";
    medication ->  manufacturedProduct.templateId as templateId,  templateId.root = '2.16.840.1.113883.10.20.1.53' "MP-templateId";
    medication -> manufacturedProduct.manufacturedMaterial as manufacturedMaterial then ManufacturedMaterialEntryContentModulePrescription(bundle, medicationRequest, medication, manufacturedMaterial, substanceAdministration) "manufacturedMaterial";
  };
  // TODO: AUTHOR1 Medication Treatment Plan Author
  medicationRequest where dosageInstruction.count() = 1 then {
    medicationRequest.dosageInstruction as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-nonstructured') ->  substanceAdministration.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.1' "normalDose";
  } "onylonedosage";
  medicationRequest.dosageInstruction as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-normal-medicationrequest') then DosageInstructionsStartStopFrequencySubstanceAdministration(dosage, substanceAdministration) "DosageSubstanceAdministration";
  // dosage for split dosing (with sequences): effectiveTime (start/stop) & routeCode
  medicationRequest.dosageInstruction first as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split-medicationrequest') -> substanceAdministration.entryRelationship as entryRelationship then DosageInstructionsEntryStartStopRoute(dosage, substanceAdministration, entryRelationship) "DosageSubstanceAdministration";
  // dosage for split dosing (with sequences): sequence number, effectiveTime (when), dose quantity, consumable
  medicationRequest.dosageInstruction as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split-medicationrequest') ->  substanceAdministration.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'COMP' then DosageInstructionsEntryDosageChangeSubstanceAdministration(dosage, substanceAdministration, entryRelationship) "DosageSubstanceAdministration";
  medicationRequest.reasonCode as reasonCode ->  substanceAdministration.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'RSON',  entryRelationship.observation as observation then TreatmentReasonEntryContentModule(reasonCode, observation) "TreatmentReasonEntryContentModule";
  medicationRequest.extension as extension where url = 'http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-ext-treatmentplan' ->  substanceAdministration.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'REFR',  entryRelationship.substanceAdministration as substanceAdministration then MTPReferenceEntryContentModule(extension, substanceAdministration) "MTP-Reference";
  // TODO: Patient Medication Instructions Contains 1.3.6.1.4.1.19376.1.5.3.1.4.3 IHE Patient Medication Instructions (DYNAMIC)
  medicationRequest.dosageInstruction as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-nonstructured') ->  substanceAdministration.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'COMP',  entryRelationship.substanceAdministration as substanceAdministration then DosageInstructionsNonStructuredEntryContentModule(dosage, substanceAdministration) "DosageInstructionsNonStructuredEntryContentModule";
  medicationRequest.note as note ->  substanceAdministration.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'COMP',  entryRelationship.act as act then AnnotationComment(note, act) "AnnotationComment";
  medicationRequest.substitution as substitution ->  substanceAdministration.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'COMP',  entryRelationship.act as act then SubstitutionRequest(substitution, act) "Substitution";
}

// source: http://build.fhir.org/ig/hl7ch/ch-emed/StructureDefinition-ch-emed-observation.html
// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.4.44
group PharmaceuticalAdviceItemEntryContentModule(source bundle : Bundle, source fhirobservation : Observation, target cdaobservation : Observation) {
  fhirobservation -> cdaobservation.classCode = 'OBS' "OBS";
  fhirobservation -> cdaobservation.moodCode = 'EVN' "EVN";
  fhirobservation ->  cdaobservation.templateId as templateId,  templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.3' "IHE-PHARM-PADV";
  fhirobservation ->  cdaobservation.templateId as templateId,  templateId.root = '2.16.756.5.30.1.1.10.4.44' "CH-PHARM-PharmaceuticalAdviceItemEntryContentModule";
  fhirobservation.identifier as identifier -> cdaobservation.id as id then IdentifierII(identifier, id) "id";
  fhirobservation.code as fhirCode -> cdaobservation.code as cdaCode then CodeableConceptCE(fhirCode, cdaCode);
  fhirobservation ->  cdaobservation.statusCode as statusCode,  statusCode.code = 'completed' "code";
  fhirobservation.effectiveDateTime as effectiveDateTime -> cdaobservation.effectiveTime as effectiveTime then {
    effectiveDateTime -> effectiveTime.value = effectiveDateTime "value";
  } "effectiveTime";
  fhirobservation.extension as extension where url = 'http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-ext-treatmentplan' ->  cdaobservation.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'REFR',  entryRelationship.substanceAdministration as substanceAdministration then MTPReferenceEntryContentModule(extension, substanceAdministration) "MTP-Reference";
  fhirobservation.extension as extension where url = 'http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-ext-medicationstatement-changed' ->  cdaobservation.entryRelationship as entryRelationship,  entryRelationship.typeCode = 'REFR' then {
    bundle.entry as entry then {
      entry.fullUrl where ($this in %extension.valueReference.reference) and $this.startsWith('urn:uuid') then {
        entry.resource as medicationStatement where $this.ofType(FHIR.MedicationStatement) -> entryRelationship.substanceAdministration as substanceAdministration then MedicationTreatmentPlanItemEntryContentModule(bundle, medicationStatement, substanceAdministration) "MedicationStatement";
      } "fullUrlAsUuid";
      entry.resource as medicationStatement where $this.ofType(FHIR.MedicationStatement) and (('MedicationStatement' + '/' + $this.id) in %extension.valueReference.reference) -> entryRelationship.substanceAdministration as substanceAdministration then MedicationTreatmentPlanItemEntryContentModule(bundle, medicationStatement, substanceAdministration) "MedicationStatement";
    };
  } "changedmtp";
  fhirobservation.note as note then {
    note.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' ->  cdaobservation.text as text,  text.reference as reference then {
      extension.valueUrl as valueUrl -> reference.value = valueUrl;
    } "narrativeLink";
    note where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) ->  cdaobservation.text as text,  text.reference as reference,  reference.value = '#refpdf' "reference";
  };
  fhirobservation.note as note -> cdaobservation.text as text then {
    note.text as noteText -> text.data = noteText;
    note.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' then {
      extension.valueUrl as valueUrl ->  text.reference as reference,  reference.value = valueUrl "reference";
    } "id";
    note where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) ->  text.reference as reference,  reference.value = '#refpdf' "reference";
  } "text";
}


Source

{
  "resourceType" : "StructureMap",
  "id" : "BundleToCdaChEmed",
  "meta" : {
    "versionId" : "2",
    "lastUpdated" : "2021-11-04T13:41:21.790+01:00"
  },
  "text" : {
    "status" : "generated",
    "div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n <pre>map &quot;http://fhir.ch/ig/cda-fhir-maps/StructureMap/BundleToCdaChEmed&quot; = &quot;BundleToCdaChEmed&quot;\n\n\n// Medication Entries\n// 2020-11-11 Michaela Ziegler, copyright ahdis ag, Apache License\n// CDA-CH-EMED: https://art-decor.org/art-decor/decor-project--cdachemed-\n// FHIR CH-EMED: http://fhir.ch/ig/ch-emed/index.html\n\nuses &quot;http://hl7.org/fhir/cda/StructureDefinition/ClinicalDocument&quot; alias ClinicalDocument as target\nuses &quot;http://hl7.org/fhir/cda/StructureDefinition/AssignedAuthor&quot; alias AssignedAuthor as target\nuses &quot;http://hl7.org/fhir/cda/StructureDefinition/AssignedEntity&quot; alias AssignedEntity as target\nuses &quot;http://hl7.org/fhir/cda/StructureDefinition/Author&quot; alias Author as target\nuses &quot;http://hl7.org/fhir/cda/StructureDefinition/CustodianOrganization&quot; alias CustodianOrganization as target\nuses &quot;http://hl7.org/fhir/cda/StructureDefinition/IVL_TS&quot; alias IVL_TS as target\nuses &quot;http://hl7.org/fhir/cda/StructureDefinition/EIVL_TS&quot; alias EIVL_TS as target\nuses &quot;http://hl7.org/fhir/cda/StructureDefinition/PatientRole&quot; alias PatientRole as target\nuses &quot;http://hl7.org/fhir/cda/StructureDefinition/RecordTarget&quot; alias RecordTarget as target\nuses &quot;http://hl7.org/fhir/cda/StructureDefinition/Section&quot; alias Section as target\nuses &quot;http://hl7.org/fhir/cda/StructureDefinition/SubstanceAdministration&quot; alias SubstanceAdministration as target\nuses &quot;http://hl7.org/fhir/cda/StructureDefinition/SXPR_TS&quot; alias SXPR_TS as target\nuses &quot;http://hl7.org/fhir/cda/StructureDefinition/Supply&quot; alias Supply as target\nuses &quot;http://hl7.org/fhir/StructureDefinition/Bundle&quot; alias Bundle as source\nuses &quot;http://hl7.org/fhir/StructureDefinition/Composition&quot; alias Composition as source\nuses &quot;http://hl7.org/fhir/StructureDefinition/Patient&quot; alias Patient as source\nuses &quot;http://hl7.org/fhir/StructureDefinition/Practitioner&quot; alias Practitioner as source\nuses &quot;http://hl7.org/fhir/StructureDefinition/Organization&quot; alias Organization as source\nuses &quot;http://hl7.org/fhir/StructureDefinition/MedicationStatement&quot; alias MedicationStatement as source\nuses &quot;http://hl7.org/fhir/StructureDefinition/Dosage&quot; alias Dosage as source\n\nimports &quot;http://fhir.ch/ig/cda-fhir-maps/StructureMap/FhirToCdaTypes&quot;\nimports &quot;http://fhir.ch/ig/cda-fhir-maps/StructureMap/BundleToCda&quot;\nimports &quot;http://fhir.ch/ig/cda-fhir-maps/StructureMap/BundleToCdaCh&quot;\n\n// source: Annotation note (e.g. http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationstatement.html)\n// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&amp;id=2.16.756.5.30.1.1.10.4.2\ngroup AnnotationComment(source note : Annotation, target act : Act) {\n note -&gt; act.classCode = 'ACT' &quot;ACT&quot;;\n note -&gt; act.moodCode = 'EVN' &quot;EVN&quot;;\n note -&gt; act.templateId as templateId, templateId.root = '2.16.756.5.30.1.1.10.4.2' &quot;templateId&quot;;\n note -&gt; act.templateId as templateId, templateId.root = '2.16.840.1.113883.10.20.1.40' &quot;templateId&quot;;\n note -&gt; act.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.2' &quot;templateId&quot;;\n note -&gt; act.code as code, code.code = '48767-8', code.codeSystem = '2.16.840.1.113883.6.1', code.displayName = 'Annotation comment', code.codeSystemName = 'LOINC' &quot;code&quot;;\n note.text as noteText -&gt; act.text as text then {\n noteText -&gt; text.data = noteText &quot;text&quot;;\n note.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' then {\n extension.valueUrl as valueUrl -&gt; text.reference as reference, reference.value = valueUrl &quot;reference&quot;;\n } &quot;id&quot;;\n note where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) -&gt; text.reference as reference, reference.value = '#refpdf' &quot;reference&quot;;\n };\n note -&gt; act.statusCode as code, code.code = 'completed' &quot;statusCode&quot;;\n}\n\n// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationstatement.html\n// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&amp;id=2.16.756.5.30.1.1.10.4.33&amp;effectiveDate=2019-12-11T11:34:24&amp;language=en-US\ngroup ManufacturedMaterialEntryContentModuleStatement(source bundle : Bundle, source medicationStatement : MedicationStatement, source medication : Medication, target manufacturedMaterial : ManufacturedMaterial) {\n medication -&gt; manufacturedMaterial.classCode = 'MMAT' &quot;MMAT&quot;;\n medication -&gt; manufacturedMaterial.determinerCode = 'KIND' &quot;KIND&quot;;\n medication -&gt; manufacturedMaterial.templateId as templateId, templateId.root = '2.16.756.5.30.1.1.10.4.33' &quot;CH-PHARM-ManufacturedMaterialContentModule&quot;;\n medication -&gt; manufacturedMaterial.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.1' &quot;templateId&quot;;\n medication.code as code then {\n code.text as text -&gt; manufacturedMaterial.name as name, name.other = text &quot;brandname&quot;;\n } &quot;name&quot;;\n medication.code as code then {\n // #mtpc.no.brandedmedication\n code.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' -&gt; manufacturedMaterial.code as code then {\n extension.valueUrl as valueUrl -&gt; code.originalText as text, text.reference as reference, reference.value = valueUrl &quot;reference&quot;;\n } &quot;id&quot;;\n code where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) -&gt; manufacturedMaterial.code as code, code.originalText as text, text.reference as reference, reference.value = '#refpdf' &quot;reference&quot;;\n code.coding as coding -&gt; manufacturedMaterial.code as ce then CodingCE(coding, ce) &quot;code&quot;;\n code where coding.exists() = false -&gt; manufacturedMaterial.code as ce, ce.nullFlavor = 'NA' &quot;nullFlavor&quot;;\n };\n medication.form as form then {\n form.coding as coding -&gt; manufacturedMaterial.formCode as formCode then CodingCE(coding, formCode) &quot;formCode&quot;;\n };\n medication.code as code -&gt; manufacturedMaterial.asContent as asContent, asContent.classCode = 'CONT', asContent.containerPackagedMedicine as containerPackagedMedicine then {\n code -&gt; containerPackagedMedicine.classCode = 'CONT' &quot;CONT&quot;;\n code -&gt; containerPackagedMedicine.determinerCode = 'INSTANCE' &quot;INSTANCE&quot;;\n code.coding as coding -&gt; containerPackagedMedicine.code as ce then CodingCE(coding, ce) &quot;pharm-code&quot;;\n code.text as text -&gt; containerPackagedMedicine.name as name, name.other = text &quot;pharm-name&quot;;\n medication.form as form then {\n form.coding as coding -&gt; containerPackagedMedicine.formCode as formCode then CodingCE(coding, formCode) &quot;pharm-formCode&quot;;\n };\n // Package size\n medication.amount as amount then {\n amount.numerator as numerator -&gt; containerPackagedMedicine.capacityQuantity as capacityQuantity then {\n numerator.value as value -&gt; capacityQuantity.value = value;\n numerator.code as unit -&gt; capacityQuantity.unit = unit &quot;unit&quot;;\n };\n };\n };\n medication.ingredient as ingredient -&gt; manufacturedMaterial.ingredient as ingredient, ingredient.classCode = 'ACTI' then {\n ingredient.itemCodeableConcept as itemCodeableConcept -&gt; ingredient.ingredient as pharmsubstance then {\n itemCodeableConcept -&gt; pharmsubstance.classCode = 'MMAT' &quot;MMAT&quot;;\n itemCodeableConcept -&gt; pharmsubstance.determinerCode = 'KIND' &quot;KIND&quot;;\n itemCodeableConcept.text as text -&gt; pharmsubstance.name as name, name.other = text &quot;name&quot;;\n itemCodeableConcept.coding as coding then {\n coding -&gt; pharmsubstance.code as ce then CodingCE(coding, ce) &quot;formCode&quot;;\n };\n } &quot;PharmSubstance&quot;;\n ingredient.strength as strength -&gt; ingredient.quantity as quantity then RatioRTOPQPQ(strength, quantity);\n };\n}\n\n// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationstatement.html\n// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&amp;id=2.16.756.5.30.1.1.10.4.34&amp;effectiveDate=2019-12-11T11:31:52&amp;language=en-US\ngroup MedicationTreatmentPlanItemEntryContentModule(source bundle : Bundle, source medicationStatement : MedicationStatement, target substanceAdministration : SubstanceAdministration) {\n medicationStatement -&gt; substanceAdministration.classCode = 'SBADM' &quot;SBADM&quot;;\n medicationStatement -&gt; substanceAdministration.moodCode = 'INT' &quot;INT&quot;;\n medicationStatement -&gt; substanceAdministration.templateId as templateId, templateId.root = '2.16.756.5.30.1.1.10.4.34' &quot;CH-PHARM-MedicationTreatmentPlanItemEntryContentModule&quot;;\n medicationStatement -&gt; substanceAdministration.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.7' &quot;IHE-PHARM-MTP&quot;;\n medicationStatement -&gt; substanceAdministration.templateId as templateId, templateId.root = '2.16.840.1.113883.10.20.1.24' &quot;CCD&quot;;\n medicationStatement -&gt; substanceAdministration.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7' &quot;PCC-MedicationEntryContentModule&quot;;\n medicationStatement.identifier as identifier -&gt; substanceAdministration.id as id then IdentifierII(identifier, id) &quot;id&quot;;\n medicationStatement.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' -&gt; substanceAdministration.text as text, text.reference as reference then {\n extension.valueUrl as valueUrl -&gt; reference.value = valueUrl;\n } &quot;narrativeLink&quot;;\n medicationStatement where extension.where(url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists().not() -&gt; substanceAdministration.text as text, text.reference as reference then {\n medicationStatement -&gt; reference.value = '#refpdf' &quot;referencetopdf&quot;;\n } &quot;cat1narrativelink&quot;;\n medicationStatement -&gt; substanceAdministration.statusCode as statusCode, statusCode.code = 'completed' &quot;code&quot;;\n medicationStatement.contained as medication where ('#' + $this.id) in %medicationStatement.medicationReference.reference -&gt; substanceAdministration.consumable as consumable, consumable.manufacturedProduct as manufacturedProduct, manufacturedProduct.classCode = 'MANU' then {\n medication -&gt; manufacturedProduct.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.2' &quot;MP-TemplateId&quot;;\n medication -&gt; manufacturedProduct.templateId as templateId, templateId.root = '2.16.840.1.113883.10.20.1.53' &quot;MP-TemplateId&quot;;\n medication -&gt; manufacturedProduct.manufacturedMaterial as manufacturedMaterial then ManufacturedMaterialEntryContentModuleStatement(bundle, medicationStatement, medication, manufacturedMaterial) &quot;manufacturedMaterial&quot;;\n };\n // TODO: AUTHOR1 Medication Treatment Plan Author\n medicationStatement where dosage.count() = 1 then {\n medicationStatement.dosage as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-nonstructured') -&gt; substanceAdministration.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.1' &quot;normalDose&quot;;\n } &quot;onylonedosage&quot;;\n // dosage for normal dosing, as no sequences are present there\n medicationStatement.dosage as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-normal') then DosageInstructionsStartStopFrequencySubstanceAdministration(dosage, substanceAdministration) &quot;DosageSubstanceAdministration&quot;;\n // dosage for split dosing (with sequences): effectiveTime (start/stop) &amp; routeCode\n medicationStatement.dosage first as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split') -&gt; substanceAdministration.entryRelationship as entryRelationship then DosageInstructionsEntryStartStopRoute(dosage, substanceAdministration, entryRelationship) &quot;DosageSubstanceAdministration&quot;;\n // dosage for split dosing (with sequences): sequence number, effectiveTime (when), dose quantity, consumable\n medicationStatement.dosage as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split') -&gt; substanceAdministration.entryRelationship as entryRelationship, entryRelationship.typeCode = 'COMP' then DosageInstructionsEntryDosageChangeSubstanceAdministration(dosage, substanceAdministration, entryRelationship) &quot;DosageSubstanceAdministration&quot;;\n medicationStatement.reasonCode as reasonCode -&gt; substanceAdministration.entryRelationship as entryRelationship, entryRelationship.typeCode = 'RSON', entryRelationship.observation as observation then TreatmentReasonEntryContentModule(reasonCode, observation) &quot;TreatmentReasonEntryContentModule&quot;;\n medicationStatement.extension as extension where url = 'http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-ext-treatmentplan' -&gt; substanceAdministration.entryRelationship as entryRelationship, entryRelationship.typeCode = 'REFR', entryRelationship.substanceAdministration as substanceAdministration then MTPReferenceEntryContentModule(extension, substanceAdministration) &quot;MTP-Reference&quot;;\n // https://github.com/ehealthsuisse/ch-emed/issues/56\n medicationStatement -&gt; substanceAdministration.repeatNumber as repeatNumber, repeatNumber.nullFlavor = 'NI' &quot;repeatNumberDefault&quot;;\n // TODO: Patient Medication Instructions Contains 1.3.6.1.4.1.19376.1.5.3.1.4.3 IHE Patient Medication Instructions (DYNAMIC)\n medicationStatement.dosage as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-nonstructured') -&gt; substanceAdministration.entryRelationship as entryRelationship, entryRelationship.typeCode = 'COMP', entryRelationship.substanceAdministration as substanceAdministration then DosageInstructionsNonStructuredEntryContentModule(dosage, substanceAdministration) &quot;DosageInstructionsNonStructuredEntryContentModule&quot;;\n medicationStatement.note as note -&gt; substanceAdministration.entryRelationship as entryRelationship, entryRelationship.typeCode = 'COMP', entryRelationship.act as act then AnnotationComment(note, act) &quot;AnnotationComment&quot;;\n medicationStatement.extension as extension where $this.url = 'http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-ext-substitution' -&gt; substanceAdministration.entryRelationship as entryRelationship, entryRelationship.typeCode = 'COMP', entryRelationship.act as act then SubstitutionStatement(extension, act) &quot;Substitution&quot;;\n}\n\n// TODO: Tapered Dose\n// medicationStatement -&gt; substanceAdministration.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.8' &quot;taperedDose&quot;;\n// source: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-normal\n// target: https://art-decor.org/art-decor/decor-templates--ch-pharm-?id=2.16.756.5.30.1.1.10.4.35\n// dosage for normal dosing (without sequences) (Statement, Prescription)\ngroup DosageInstructionsStartStopFrequencySubstanceAdministration(source dosage : Dosage, target substanceAdministration : SubstanceAdministration) {\n dosage -&gt; substanceAdministration.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.1' &quot;normalDose&quot;;\n dosage as dosage -&gt; substanceAdministration as substanceAdministration then EffectiveTimeStartEnd(dosage, substanceAdministration) &quot;effectiveTimeStartEnd&quot;;\n dosage as dosage -&gt; substanceAdministration as substanceAdministration then EffectiveTimeWhenNormal(dosage, substanceAdministration) &quot;effectiveTimeWhen&quot;;\n dosage.route as route -&gt; substanceAdministration.routeCode as routeCode then CodeableConceptCE(route, routeCode);\n dosage as dosage -&gt; substanceAdministration as substanceAdministration then DoseQuantity(dosage, substanceAdministration) &quot;doseQuantity&quot;;\n}\n\n// source: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split\n// target: https://art-decor.org/art-decor/decor-templates--ch-pharm-?id=2.16.756.5.30.1.1.10.4.36\n// dosage for split dosing: effectiveTime (start/stop) &amp; routeCode (Statement, Prescription)\ngroup DosageInstructionsEntryStartStopRoute(source dosage : Dosage, target substanceAdministration : substanceAdministration, target entry : entryRelationship) {\n // if the FHIR doucment has no dosage templateId -&gt; create templateId for split dose\n dosage -&gt; substanceAdministration.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.9' &quot;splitDose&quot;;\n dosage as dosage -&gt; substanceAdministration as substanceAdministration then EffectiveTimeStartEnd(dosage, substanceAdministration) &quot;effectiveTimeStartEnd&quot;;\n dosage.route as route -&gt; substanceAdministration.routeCode as routeCode then CodeableConceptCE(route, routeCode);\n}\n\n// source: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split\n// target: https://art-decor.org/art-decor/decor-templates--ch-pharm-?id=2.16.756.5.30.1.1.10.4.36\n// dosage for split dosing: sequence number, effectiveTime (when), dose quantity, consumable (Statement, Prescription)\ngroup DosageInstructionsEntryDosageChangeSubstanceAdministration(source dosage : Dosage, target substanceAdministration : substanceAdministration, target entry : entryRelationship) {\n dosage.sequence as sequence -&gt; entry.sequenceNumber as sequenceNumber, sequenceNumber.value = sequence;\n dosage -&gt; entry.substanceAdministration as substanceAdministration, substanceAdministration.classCode = 'SBADM', substanceAdministration.moodCode = 'INT' then {\n dosage as dosage -&gt; substanceAdministration as substanceAdministration then EffectiveTimeWhenSplit(dosage, substanceAdministration) &quot;effectiveTimeWhen&quot;;\n dosage as dosage -&gt; substanceAdministration as substanceAdministration then DoseQuantity(dosage, substanceAdministration) &quot;doseQuantity&quot;;\n dosage as dosage -&gt; substanceAdministration as substanceAdministration, substanceAdministration.consumable as consumable, consumable.manufacturedProduct as manufacturedProduct, manufacturedProduct.manufacturedMaterial as manufacturedMaterial, manufacturedMaterial.nullFlavor = 'NA' &quot;consumable&quot;;\n } &quot;dosage&quot;;\n}\n\n// effective time low and high for dosage (Statement, Prescription)\ngroup EffectiveTimeStartEnd(source dosage : Dosage, target substanceAdministration : SubstanceAdministration) {\n dosage.timing as timing then {\n timing.repeat as repeat then {\n repeat.bounds : Period as bounds -&gt; substanceAdministration.effectiveTime = create('IVL_TS') as effectiveTime then {\n bounds.start as start -&gt; effectiveTime.low as low then DateTS(start, low) &quot;low&quot;;\n bounds where start.exists().not() -&gt; effectiveTime.low as low, low.nullFlavor = 'UNK' &quot;NullFlavorLow&quot;;\n bounds.end as end -&gt; effectiveTime.high as high then DateTS(end, high) &quot;high&quot;;\n bounds where end.exists().not() -&gt; effectiveTime.high as high, high.nullFlavor = 'UNK' &quot;NullFlavorhigh&quot;;\n };\n };\n };\n}\n\n// dose quantity for dosage (application schema) (Statement)\ngroup DoseQuantity(source dosage : Dosage, target substanceAdministration : SubstanceAdministration) {\n dosage.doseAndRate as doseAndRate -&gt; substanceAdministration.doseQuantity as doseQuantity then {\n doseAndRate.dose : Quantity as quantity then {\n quantity.value as value -&gt; doseQuantity.value = value;\n quantity.code as code -&gt; doseQuantity.unit = code;\n } &quot;quantity&quot;;\n } &quot;doseQuantity&quot;;\n}\n\n// source: reasonCode Coding (e.g. http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-medicationstatement)\n// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&amp;id=2.16.756.5.30.1.1.10.4.41\n// Treatment Reason (Statement, Prescription)\ngroup TreatmentReasonEntryContentModule(source reasonCode : Coding, target observation : Observation) {\n reasonCode -&gt; observation.classCode = 'OBS' &quot;OBS&quot;;\n reasonCode -&gt; observation.moodCode = 'EVN' &quot;EVN&quot;;\n reasonCode -&gt; observation.templateId as templateId, templateId.root = '2.16.756.5.30.1.1.10.4.41' &quot;TreatmentReasonEntryContentModule&quot;;\n reasonCode -&gt; observation.code as code, code.code = '75326-9', code.codeSystem = '2.16.840.1.113883.6.1', code.displayName = 'Problem', code.codeSystemName = 'LOINC' &quot;code&quot;;\n reasonCode.text as reasonText -&gt; observation.text as text then {\n reasonText -&gt; text.data = reasonText &quot;text&quot;;\n reasonCode.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' then {\n extension.valueUrl as valueUrl -&gt; text.reference as reference, reference.value = valueUrl &quot;reference&quot;;\n } &quot;id&quot;;\n reasonCode where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) -&gt; text.reference as reference, reference.value = '#refpdf' &quot;reference&quot;;\n };\n reasonCode -&gt; observation.statusCode as code, code.code = 'completed' &quot;statusCode&quot;;\n}\n\n// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-ext-treatmentplan.html\n// target: https://art-decor.org/art-decor/decor-templates--ch-pharm-?section=templates&amp;id=2.16.756.5.30.1.1.10.4.45&amp;effectiveDate=2017-01-10T15:34:25&amp;language=en-US\ngroup MTPReferenceEntryContentModule(source ext : Extension, target substanceAdministration : SubstanceAdministration) {\n ext -&gt; substanceAdministration.classCode = 'SBADM' &quot;SBADM&quot;;\n ext -&gt; substanceAdministration.moodCode = 'INT' &quot;INT&quot;;\n ext -&gt; substanceAdministration.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.10' &quot;referenceTo-MTP-PlanItemGeneralSpecificationTemplateId&quot;;\n ext -&gt; substanceAdministration.templateId as templateId, templateId.root = '2.16.756.5.30.1.1.10.4.45' &quot;CH-PHARM-templateId&quot;;\n ext.extension as extension where $this.url = 'id' then {\n extension.valueIdentifier as valueIdentifier -&gt; substanceAdministration.id as id then IdentifierII(valueIdentifier, id) &quot;id&quot;;\n } &quot;id&quot;;\n ext -&gt; substanceAdministration.code as code, code.code = 'MTPItem', code.codeSystem = '1.3.6.1.4.1.19376.1.9.2.2', code.displayName = 'Medication Treatment Plan Item', code.codeSystemName = 'IHE Pharmacy Item Type List' &quot;code&quot;;\n ext -&gt; substanceAdministration.consumable as consumable, consumable.manufacturedProduct as manufacturedProduct, manufacturedProduct.manufacturedMaterial as manufacturedMaterial, manufacturedMaterial.nullFlavor = 'NA' &quot;consumable&quot;;\n ext.extension as extension where $this.url = 'externalDocumentId' then {\n extension.valueIdentifier as valueIdentifier -&gt; substanceAdministration.reference as reference, reference.typeCode = 'XCRPT', reference.externalDocument as externalDocument, externalDocument.id as id then IdentifierII(valueIdentifier, id) &quot;id&quot;;\n } &quot;externalDocumentId&quot;;\n}\n\n// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-dosage-nonstructured.html\n// target: https://art-decor.org/art-decor/decor-templates--ch-pharm-?section=templates&amp;id=2.16.756.5.30.1.1.10.4.52\n// Dosage Instruction (Statement, Prescription)\ngroup DosageInstructionsNonStructuredEntryContentModule(source dosage : Dosage, target substanceAdministration : SubstanceAdministration) {\n dosage -&gt; substanceAdministration.classCode = 'SBADM' &quot;SBADM&quot;;\n dosage -&gt; substanceAdministration.moodCode = 'INT' &quot;INT&quot;;\n dosage -&gt; substanceAdministration.templateId as templateId, templateId.root = '2.16.756.5.30.1.1.10.4.52' &quot;templateId&quot;;\n dosage.text as noteText -&gt; substanceAdministration.text as text then {\n noteText -&gt; text.data = noteText &quot;text&quot;;\n dosage.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' then {\n extension.valueUrl as valueUrl -&gt; text.reference as reference, reference.value = valueUrl &quot;reference&quot;;\n } &quot;id&quot;;\n dosage where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) -&gt; text.reference as reference, reference.value = '#refpdf' &quot;reference&quot;;\n };\n dosage -&gt; substanceAdministration.consumable as consumable, consumable.manufacturedProduct as manufacturedProduct, manufacturedProduct.manufacturedMaterial as manufacturedMaterial, manufacturedMaterial.nullFlavor = 'NA' &quot;consumable&quot;;\n}\n\n// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationdispense.html\n// target: Substitution act Contains 1.3.6.1.4.1.19376.1.9.1.3.9.2 IHE Substitution Act Content Module\n// Substitution (Dispense)\ngroup SubstitutionDispense(source substitution : Substitution, target act : Act) {\n substitution -&gt; act.classCode = 'ACT' &quot;ACT&quot;;\n substitution -&gt; act.moodCode = 'EVN' &quot;EVN&quot;;\n substitution -&gt; act.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.9.2' &quot;templateId&quot;;\n substitution.type as type -&gt; act.code as code then CodeableConceptCE(type, code) &quot;substitution&quot;;\n substitution -&gt; act.statusCode as statusCode, statusCode.code = 'completed' &quot;statusCode&quot;;\n}\n\n// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationdispense.html\n// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&amp;id=2.16.756.5.30.1.1.10.4.33&amp;effectiveDate=2019-12-11T11:34:24&amp;language=en-US\ngroup ManufacturedMaterialEntryContentModuleDispense(source bundle : Bundle, source medicationDispense : MedicationDispense, source medication : Medication, target manufacturedMaterial : ManufacturedMaterial) {\n medication -&gt; manufacturedMaterial.classCode = 'MMAT' &quot;MMAT&quot;;\n medication -&gt; manufacturedMaterial.determinerCode = 'KIND' &quot;KIND&quot;;\n medication -&gt; manufacturedMaterial.templateId as templateId, templateId.root = '2.16.756.5.30.1.1.10.4.33' &quot;CH-PHARM-ManufacturedMaterialContentModule&quot;;\n medication -&gt; manufacturedMaterial.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.1' &quot;templateId&quot;;\n medication.code as code then {\n code.text as text -&gt; manufacturedMaterial.name as name, name.other = text &quot;brandname&quot;;\n } &quot;name&quot;;\n medication.code as code then {\n // #dis.no.brandedmedication\n code.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' -&gt; manufacturedMaterial.code as code then {\n extension.valueUrl as valueUrl -&gt; code.originalText as text, text.reference as reference, reference.value = valueUrl &quot;reference&quot;;\n } &quot;id&quot;;\n code where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) -&gt; manufacturedMaterial.code as code, code.originalText as text, text.reference as reference, reference.value = '#refpdf' &quot;reference&quot;;\n code.coding as coding -&gt; manufacturedMaterial.code as ce then CodingCE(coding, ce) &quot;code&quot;;\n };\n medication.form as form then {\n form.coding as coding -&gt; manufacturedMaterial.formCode as formCode then CodingCE(coding, formCode) &quot;formCode&quot;;\n };\n medication.code as code -&gt; manufacturedMaterial.asContent as asContent, asContent.classCode = 'CONT', asContent.containerPackagedMedicine as containerPackagedMedicine then {\n code -&gt; containerPackagedMedicine.classCode = 'CONT' &quot;CONT&quot;;\n code -&gt; containerPackagedMedicine.determinerCode = 'INSTANCE' &quot;INSTANCE&quot;;\n code.coding as coding -&gt; containerPackagedMedicine.code as ce then CodingCE(coding, ce) &quot;pharm-code&quot;;\n code.text as text -&gt; containerPackagedMedicine.name as name, name.other = text &quot;pharm-name&quot;;\n medication.form as form then {\n form.coding as coding -&gt; containerPackagedMedicine.formCode as formCode then CodingCE(coding, formCode) &quot;pharm-formCode&quot;;\n };\n // Package size\n medication.amount as amount then {\n amount.numerator as numerator -&gt; containerPackagedMedicine.capacityQuantity as capacityQuantity then {\n numerator.value as value -&gt; capacityQuantity.value = value;\n numerator.code as unit -&gt; capacityQuantity.unit = unit &quot;unit&quot;;\n };\n };\n };\n medication.ingredient as ingredient -&gt; manufacturedMaterial.ingredient as ingredient, ingredient.classCode = 'ACTI' then {\n ingredient.itemCodeableConcept as itemCodeableConcept -&gt; ingredient.ingredient as pharmsubstance then {\n itemCodeableConcept -&gt; pharmsubstance.classCode = 'MMAT' &quot;MMAT&quot;;\n itemCodeableConcept -&gt; pharmsubstance.determinerCode = 'KIND' &quot;KIND&quot;;\n itemCodeableConcept.text as text -&gt; pharmsubstance.name as name, name.other = text &quot;name&quot;;\n itemCodeableConcept.coding as coding then {\n coding -&gt; pharmsubstance.code as ce then CodingCE(coding, ce) &quot;formCode&quot;;\n };\n } &quot;PharmSubstance&quot;;\n ingredient.strength as strength -&gt; ingredient.quantity as quantity then RatioRTOPQPQ(strength, quantity);\n };\n}\n\n// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationdispense.html\n// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&amp;id=2.16.756.5.30.1.1.10.4.42\ngroup DispenseItemEntryContentModule(source bundle : Bundle, source medicationDispense : MedicationDispense, target supply : Supply) {\n medicationDispense -&gt; supply.classCode = 'SPLY' &quot;SPLY&quot;;\n medicationDispense -&gt; supply.moodCode = 'EVN' &quot;EVN&quot;;\n medicationDispense -&gt; supply.templateId as templateId, templateId.root = '2.16.756.5.30.1.1.10.4.42' &quot;CH-PHARM-DispenseItemEntryContentModule&quot;;\n medicationDispense -&gt; supply.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.4' &quot;IHE-PHARM-DIS&quot;;\n medicationDispense -&gt; supply.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.3' &quot;supplyEntry&quot;;\n medicationDispense -&gt; supply.templateId as templateId, templateId.root = '2.16.840.1.113883.10.20.1.34' &quot;CCD&quot;;\n medicationDispense.identifier as identifier -&gt; supply.id as id then IdentifierII(identifier, id) &quot;id&quot;;\n medicationDispense.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' -&gt; supply.text as text, text.reference as reference then {\n extension.valueUrl as valueUrl -&gt; reference.value = valueUrl;\n } &quot;narrativeLink&quot;;\n medicationDispense where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) -&gt; supply.text as text, text.reference as reference, text.reference as reference, reference.value = '#refpdf' &quot;reference&quot;;\n medicationDispense.contained as medication where ('#' + $this.id) in %medicationDispense.medicationReference.reference -&gt; supply.product as product, product.manufacturedProduct as manufacturedProduct, manufacturedProduct.classCode = 'MANU' then {\n medication -&gt; manufacturedProduct.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.2' &quot;MP-TemplateId&quot;;\n medication -&gt; manufacturedProduct.templateId as templateId, templateId.root = '2.16.840.1.113883.10.20.1.53' &quot;MP-TemplateId&quot;;\n medication -&gt; manufacturedProduct.manufacturedMaterial as manufacturedMaterial then ManufacturedMaterialEntryContentModuleDispense(bundle, medicationDispense, medication, manufacturedMaterial) &quot;manufacturedMaterial&quot;;\n };\n // TODO: AUTHOR1 Medication Treatment Plan Author\n medicationDispense.extension as extension where url = 'http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-ext-treatmentplan' -&gt; supply.entryRelationship as entryRelationship, entryRelationship.typeCode = 'REFR', entryRelationship.substanceAdministration as substanceAdministration then MTPReferenceEntryContentModule(extension, substanceAdministration) &quot;MTP-Reference&quot;;\n // #24 missing template it if ch-emed-dosage-nonstructured\n medicationDispense where dosageInstruction.count() = 1 then {\n medicationDispense.dosageInstruction as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-nonstructured') -&gt; substanceAdministration.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.1' &quot;normalDose&quot;;\n } &quot;onylonedosage&quot;;\n // dosage for normal dosing, as no sequences are present there\n medicationDispense.dosageInstruction as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-normal') then DosageInstructionsStartStopFrequencySupply(dosage, supply) &quot;DosageSubstanceAdministration&quot;;\n // dosage for split dosing, as sequences are present there\n medicationDispense -&gt; supply.entryRelationship as entryRelationship then {\n medicationDispense -&gt; entryRelationship.substanceAdministration as substanceAdministration then {\n // split dosing (with sequences): effectiveTime (start/stop) &amp; routeCode &amp; consumable\n medicationDispense.dosageInstruction first as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split') -&gt; substanceAdministration then DosageInstructionsEntryStartStopRouteConsumable(dosage, entryRelationship, substanceAdministration) &quot;DosageSubstanceAdministration&quot;;\n // split dosing (with sequences): sequence number, effectiveTime (when), dose quantity, consumable\n medicationDispense.dosageInstruction as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split') -&gt; substanceAdministration.entryRelationship as entryRelationship, entryRelationship.typeCode = 'COMP' then DosageInstructionsEntryDosageChangeEntryRelationship(dosage, entryRelationship) &quot;DosageSubstanceAdministration&quot;;\n } &quot;substanceAdministration&quot;;\n } &quot;entryRelationship&quot;;\n // TODO: Precondition Criterion\n medicationDispense.dosageInstruction as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-nonstructured') -&gt; supply.entryRelationship as entryRelationship, entryRelationship.typeCode = 'COMP', entryRelationship.substanceAdministration as substanceAdministration then DosageInstructionsNonStructuredEntryContentModule(dosage, substanceAdministration) &quot;DosageInstructionsNonStructuredEntryContentModule&quot;;\n // Number of packages\n medicationDispense.quantity as quantity -&gt; supply.quantity as supplyQuantity then {\n quantity.value as value -&gt; supplyQuantity.value = value;\n };\n medicationDispense.note as note -&gt; supply.entryRelationship as entryRelationship, entryRelationship.typeCode = 'COMP', entryRelationship.act as act then AnnotationComment(note, act) &quot;AnnotationComment&quot;;\n medicationDispense.substitution as substitution -&gt; supply.entryRelationship as entryRelationship, entryRelationship.typeCode = 'COMP', entryRelationship.act as act then SubstitutionDispense(substitution, act) &quot;Substitution&quot;;\n}\n\n// source: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-normal\n// target: https://art-decor.org/art-decor/decor-templates--ch-pharm-?id=2.16.756.5.30.1.1.10.4.35\n// dosage for normal dosing (without sequences) (Dispense)\ngroup DosageInstructionsStartStopFrequencySupply(source dosage : Dosage, target supply : Supply) {\n dosage -&gt; supply.entryRelationship as entryRelationship then {\n dosage -&gt; entryRelationship.typeCode = 'COMP' &quot;COMP&quot;;\n dosage -&gt; entryRelationship.substanceAdministration as substanceAdministration then {\n dosage -&gt; substanceAdministration.classCode = 'SBADM' &quot;SBADM&quot;;\n dosage -&gt; substanceAdministration.moodCode = 'INT' &quot;INT&quot;;\n dosage -&gt; substanceAdministration.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.6' &quot;templateId&quot;;\n dosage -&gt; substanceAdministration.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.1' &quot;normalDose&quot;;\n dosage -&gt; substanceAdministration as substanceAdministration then EffectiveTimeStartEnd(dosage, substanceAdministration) &quot;effectiveTimeStartEnd&quot;;\n dosage -&gt; substanceAdministration as substanceAdministration then EffectiveTimeWhenNormal(dosage, substanceAdministration) &quot;effectiveTimeWhen&quot;;\n dosage.route as route -&gt; substanceAdministration.routeCode as routeCode then CodeableConceptCE(route, routeCode);\n dosage -&gt; substanceAdministration as substanceAdministration then DoseQuantity(dosage, substanceAdministration) &quot;doseQuantity&quot;;\n dosage -&gt; substanceAdministration as substanceAdministration, substanceAdministration.consumable as consumable, consumable.manufacturedProduct as manufacturedProduct, manufacturedProduct.manufacturedMaterial as manufacturedMaterial, manufacturedMaterial.nullFlavor = 'NA' &quot;consumable&quot;;\n } &quot;substanceAdministration&quot;;\n } &quot;entryRelationship&quot;;\n}\n\n// source: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split\n// target: https://art-decor.org/art-decor/decor-templates--ch-pharm-?id=2.16.756.5.30.1.1.10.4.36\n// dosage for split dosing: effectiveTime (start/stop) &amp; routeCode &amp; consumable (Dispense)\ngroup DosageInstructionsEntryStartStopRouteConsumable(source dosage : Dosage, target entryRelationship : entryRelationship, target substanceAdministration : SubstanceAdministration) {\n dosage -&gt; entryRelationship.typeCode = 'COMP' &quot;COMP&quot;;\n dosage -&gt; substanceAdministration.classCode = 'SBADM' &quot;SBADM&quot;;\n dosage -&gt; substanceAdministration.moodCode = 'INT' &quot;INT&quot;;\n dosage -&gt; substanceAdministration.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.6' &quot;templateId&quot;;\n dosage -&gt; substanceAdministration.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.9' &quot;splitDose&quot;;\n dosage -&gt; substanceAdministration as substanceAdministration then EffectiveTimeStartEnd(dosage, substanceAdministration) &quot;effectiveTimeStartEnd&quot;;\n dosage.route as route -&gt; substanceAdministration.routeCode as routeCode then CodeableConceptCE(route, routeCode);\n dosage -&gt; substanceAdministration.consumable as consumable, consumable.manufacturedProduct as manufacturedProduct, manufacturedProduct.manufacturedMaterial as manufacturedMaterial, manufacturedMaterial.nullFlavor = 'NA' &quot;consumable&quot;;\n}\n\n// source: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split\n// target: https://art-decor.org/art-decor/decor-templates--ch-pharm-?id=2.16.756.5.30.1.1.10.4.36\n// dosage for split dosing: sequence number, effectiveTime (when), dose quantity, consumable (Dispense)\ngroup DosageInstructionsEntryDosageChangeEntryRelationship(source dosage : Dosage, target entryRelationship : entryRelationship) {\n dosage.sequence as sequence -&gt; entryRelationship.sequenceNumber as sequenceNumber, sequenceNumber.value = sequence;\n dosage -&gt; entryRelationship.substanceAdministration as substanceAdministration, substanceAdministration.classCode = 'SBADM', substanceAdministration.moodCode = 'INT' then {\n dosage as dosage -&gt; substanceAdministration then EffectiveTimeWhenSplit(dosage, substanceAdministration) &quot;effectiveTimeWhen&quot;;\n dosage as dosage -&gt; substanceAdministration then DoseQuantity(dosage, substanceAdministration) &quot;doseQuantity&quot;;\n dosage as dosage -&gt; substanceAdministration.consumable as consumable, consumable.manufacturedProduct as manufacturedProduct, manufacturedProduct.manufacturedMaterial as manufacturedMaterial, manufacturedMaterial.nullFlavor = 'NA' &quot;consumable&quot;;\n } &quot;dosage&quot;;\n}\n\n// effective time when for normal dosage (Dispense, Statement, Prescription)\ngroup EffectiveTimeWhenNormal(source dosage : Dosage, target substanceAdministration : SubstanceAdministration) {\n dosage.timing as timing then {\n timing.repeat as repeat then {\n repeat where $this.when.count() = 1 -&gt; substanceAdministration.effectiveTime = create('EIVL_TS') as effectiveTime, effectiveTime.operator = 'A' then {\n repeat.when as when -&gt; effectiveTime.event as event, event.code = when;\n } &quot;when&quot;;\n repeat where $this.when.count() &gt; 1 -&gt; substanceAdministration.effectiveTime = create('SXPR_TS') as effectiveTime, effectiveTime.operator = 'A' then {\n repeat.when first as when -&gt; effectiveTime.comp = create('EIVL_TS') as comp then {\n when -&gt; comp.event as event, event.code = when &quot;when&quot;;\n } &quot;comp&quot;;\n repeat.when not_first as when -&gt; effectiveTime.comp = create('EIVL_TS') as comp, comp.operator = 'I' then {\n when -&gt; comp.event as event, event.code = when &quot;when&quot;;\n } &quot;compnotfirst&quot;;\n } &quot;when&quot;;\n };\n };\n}\n\n// effective time when for split dosage (Dispense, Statement, Prescription)\ngroup EffectiveTimeWhenSplit(source dosage : Dosage, target substanceAdministration : SubstanceAdministration) {\n dosage.timing as timing then {\n timing.repeat as repeat then {\n repeat where $this.when.count() = 1 -&gt; substanceAdministration.effectiveTime = create('EIVL_TS') as effectiveTime then {\n repeat.when as when -&gt; effectiveTime.event as event, event.code = when;\n } &quot;when&quot;;\n repeat where $this.when.count() &gt; 1 -&gt; substanceAdministration.effectiveTime = create('SXPR_TS') as effectiveTime, effectiveTime.operator = 'A' then {\n repeat.when first as when -&gt; effectiveTime.comp = create('EIVL_TS') as comp then {\n when -&gt; comp.event as event, event.code = when &quot;when&quot;;\n } &quot;comp&quot;;\n repeat.when not_first as when -&gt; effectiveTime.comp = create('EIVL_TS') as comp, comp.operator = 'I' then {\n when -&gt; comp.event as event, event.code = when &quot;when&quot;;\n } &quot;compnotfirst&quot;;\n } &quot;when&quot;;\n };\n };\n}\n\n// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationrequest.html\n// target: Substitution permission Contains 1.3.6.1.4.1.19376.1.9.1.3.9.1 IHE Substitution Permission Content Module\ngroup SubstitutionRequest(source substitution : Substitution, target act : Act) {\n substitution -&gt; act.classCode = 'ACT' &quot;ACT&quot;;\n substitution -&gt; act.moodCode = 'DEF' &quot;DEF&quot;;\n substitution -&gt; act.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.9.1' &quot;templateId&quot;;\n substitution.allowedCodeableConcept as allowedCC -&gt; act.code as code then CodeableConceptCE(allowedCC, code) &quot;substitution&quot;;\n substitution -&gt; act.statusCode as statusCode, statusCode.code = 'completed' &quot;statusCode&quot;;\n}\n\n// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationrequest.html\n// target: Substitution permission Contains 1.3.6.1.4.1.19376.1.9.1.3.9.1 IHE Substitution Permission Content Module\ngroup SubstitutionStatement(source extension : Extension, target act : Act) {\n extension -&gt; act.classCode = 'ACT' &quot;ACT&quot;;\n extension -&gt; act.moodCode = 'DEF' &quot;DEF&quot;;\n extension -&gt; act.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.9.1' &quot;templateId&quot;;\n extension.valueCodeableConcept as valueCC -&gt; act.code as code then CodeableConceptCE(valueCC, code) &quot;extension&quot;;\n extension -&gt; act.statusCode as statusCode, statusCode.code = 'completed' &quot;statusCode&quot;;\n}\n\n// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationrequest.html\n// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?id=2.16.756.5.30.1.1.10.4.38\ngroup PrescribedQuantity(source dispenseRequest : DispenseRequest, target supply : Supply) {\n dispenseRequest -&gt; supply.classCode = 'SPLY' &quot;SPLY&quot;;\n dispenseRequest -&gt; supply.moodCode = 'RQO' &quot;RQO&quot;;\n dispenseRequest -&gt; supply.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.8' &quot;templateId&quot;;\n dispenseRequest -&gt; supply.independentInd as independentInd, independentInd.value = 'false' &quot;independentInd&quot;;\n // Number of packages\n dispenseRequest.quantity as quantity -&gt; supply.quantity as quant then {\n quantity.value as value -&gt; quant.value = value;\n };\n}\n\n// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationrequest.html\n// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?id=2.16.756.5.30.1.1.10.4.38\ngroup PrescribedQuantityUnit(source dispenseRequest : DispenseRequest, target supply : Supply) {\n dispenseRequest -&gt; supply.classCode = 'SPLY' &quot;SPLY&quot;;\n dispenseRequest -&gt; supply.moodCode = 'RQO' &quot;RQO&quot;;\n dispenseRequest -&gt; supply.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.8' &quot;TemplateId&quot;;\n dispenseRequest -&gt; supply.independentInd as independentInd, independentInd.value = 'false' &quot;independentInd&quot;;\n // Number of packages\n dispenseRequest.quantity as quantity -&gt; supply.quantity as quant then {\n quantity.value as value -&gt; quant.value = value;\n quantity.unit as unit -&gt; quant.unit = unit;\n };\n}\n\n// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationrequest.html\n// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&amp;id=2.16.756.5.30.1.1.10.4.33\ngroup ManufacturedMaterialEntryContentModulePrescription(source bundle : Bundle, source medicationRequest : MedicationRequest, source medication : Medication, target manufacturedMaterial : ManufacturedMaterial, target substanceAdministration : SubstanceAdministration) {\n medication -&gt; manufacturedMaterial.classCode = 'MMAT' &quot;MMAT&quot;;\n medication -&gt; manufacturedMaterial.determinerCode = 'KIND' &quot;KIND&quot;;\n medication -&gt; manufacturedMaterial.templateId as templateId, templateId.root = '2.16.756.5.30.1.1.10.4.33' &quot;CH-PHARM-ManufacturedMaterialContentModule&quot;;\n medication -&gt; manufacturedMaterial.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.1' &quot;templateId&quot;;\n medication.code as code then {\n code.text as text -&gt; manufacturedMaterial.name as name, name.other = text &quot;brandname&quot;;\n } &quot;name&quot;;\n medication.code as code then {\n // #pre.no.brandedmedication\n code.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' -&gt; manufacturedMaterial.code as code then {\n extension.valueUrl as valueUrl -&gt; code.originalText as text, text.reference as reference, reference.value = valueUrl &quot;reference&quot;;\n } &quot;id&quot;;\n code where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) -&gt; manufacturedMaterial.code as code, code.originalText as text, text.reference as reference, reference.value = '#refpdf' &quot;reference&quot;;\n code.coding as coding -&gt; manufacturedMaterial.code as ce then CodingCE(coding, ce) &quot;code&quot;;\n };\n medication.form as form then {\n form.coding as coding -&gt; manufacturedMaterial.formCode as formCode then CodingCE(coding, formCode) &quot;formCode&quot;;\n };\n medication.code as code -&gt; manufacturedMaterial.asContent as asContent, asContent.classCode = 'CONT', asContent.containerPackagedMedicine as containerPackagedMedicine then {\n code -&gt; containerPackagedMedicine.classCode = 'CONT' &quot;CONT&quot;;\n code -&gt; containerPackagedMedicine.determinerCode = 'INSTANCE' &quot;INSTANCE&quot;;\n code.coding as coding -&gt; containerPackagedMedicine.code as ce then CodingCE(coding, ce) &quot;pharm-code&quot;;\n code.text as text -&gt; containerPackagedMedicine.name as name, name.other = text &quot;pharm-name&quot;;\n medication.form as form then {\n form.coding as coding -&gt; containerPackagedMedicine.formCode as formCode then CodingCE(coding, formCode) &quot;pharm-formCode&quot;;\n };\n // Package size\n medication.amount as amount then {\n amount.numerator as numerator -&gt; containerPackagedMedicine.capacityQuantity as capacityQuantity then {\n numerator.value as value -&gt; capacityQuantity.value = value;\n numerator.code as unit -&gt; capacityQuantity.unit = unit &quot;unit&quot;;\n };\n // IHE-DIS: Case 1: If the product-element contains package information, the unit attribute is not be present\n medicationRequest.dispenseRequest as dispenseRequest -&gt; substanceAdministration.entryRelationship as entryRelationship, entryRelationship.typeCode = 'COMP', entryRelationship.supply as supply then PrescribedQuantity(dispenseRequest, supply) &quot;PrescribedQuantity&quot;;\n };\n // IHE-DIS: Case 2: If the product-element does not contain package information, the unit attribut is present and the value SHALL be out of the UCUM code system\n medication where $this.amount.exists() = false then {\n medicationRequest.dispenseRequest as dispenseRequest -&gt; substanceAdministration.entryRelationship as entryRelationship, entryRelationship.typeCode = 'COMP', entryRelationship.supply as supply then PrescribedQuantityUnit(dispenseRequest, supply) &quot;PrescribedQuantityUnit&quot;;\n } &quot;noAmount&quot;;\n };\n medication.ingredient as ingredient -&gt; manufacturedMaterial.ingredient as ingredient, ingredient.classCode = 'ACTI' then {\n ingredient.itemCodeableConcept as itemCodeableConcept -&gt; ingredient.ingredient as pharmsubstance then {\n itemCodeableConcept -&gt; pharmsubstance.classCode = 'MMAT' &quot;MMAT&quot;;\n itemCodeableConcept -&gt; pharmsubstance.determinerCode = 'KIND' &quot;KIND&quot;;\n itemCodeableConcept.text as text -&gt; pharmsubstance.name as name, name.other = text &quot;name&quot;;\n itemCodeableConcept.coding as coding then {\n coding -&gt; pharmsubstance.code as ce then CodingCE(coding, ce) &quot;formCode&quot;;\n };\n } &quot;PharmSubstance&quot;;\n ingredient.strength as strength -&gt; ingredient.quantity as quantity then RatioRTOPQPQ(strength, quantity);\n };\n}\n\n// source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationrequest.html\n// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&amp;id=2.16.756.5.30.1.1.10.4.43\ngroup PrescriptionItemEntryContentModule(source bundle : Bundle, source medicationRequest : MedicationRequest, target substanceAdministration : SubstanceAdministration) {\n medicationRequest -&gt; substanceAdministration.classCode = 'SBADM' &quot;SBADM&quot;;\n medicationRequest -&gt; substanceAdministration.moodCode = 'INT' &quot;INT&quot;;\n medicationRequest -&gt; substanceAdministration.templateId as templateId, templateId.root = '2.16.756.5.30.1.1.10.4.43' &quot;CH-PHARM-PrescriptionItemEntryContentModule&quot;;\n medicationRequest -&gt; substanceAdministration.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.2' &quot;PrescriptionItemEntryTemplateId&quot;;\n medicationRequest -&gt; substanceAdministration.templateId as templateId, templateId.root = '2.16.840.1.113883.10.20.1.24' &quot;CCD&quot;;\n medicationRequest -&gt; substanceAdministration.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7' &quot;PCC-MedicationEntryContentModule&quot;;\n medicationRequest.identifier as identifier -&gt; substanceAdministration.id as id then IdentifierII(identifier, id) &quot;id&quot;;\n medicationRequest.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' -&gt; substanceAdministration.text as text, text.reference as reference then {\n extension.valueUrl as valueUrl -&gt; reference.value = valueUrl;\n } &quot;narrativeLink&quot;;\n medicationRequest where extension.where(url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists().not() -&gt; substanceAdministration.text as text, text.reference as reference then {\n medicationRequest -&gt; reference.value = '#refpdf' &quot;referencetopdf&quot;;\n } &quot;cat1narrativelink&quot;;\n medicationRequest -&gt; substanceAdministration.statusCode as statusCode, statusCode.code = 'completed' &quot;code&quot;;\n medicationRequest.dispenseRequest as dispenseRequest -&gt; substanceAdministration.repeatNumber as repeatNumber then {\n dispenseRequest.numberOfRepeatsAllowed as number -&gt; repeatNumber.value = number &quot;repeatNumber&quot;;\n dispenseRequest where numberOfRepeatsAllowed.exists() = false -&gt; repeatNumber.nullFlavor = 'NI' &quot;repeatNumberNull&quot;;\n };\n medicationRequest.contained as medication where ('#' + $this.id) in %medicationRequest.medicationReference.reference -&gt; substanceAdministration.consumable as consumable, consumable.manufacturedProduct as manufacturedProduct, manufacturedProduct.classCode = 'MANU' then {\n medication -&gt; manufacturedProduct.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.2' &quot;MP-templateId&quot;;\n medication -&gt; manufacturedProduct.templateId as templateId, templateId.root = '2.16.840.1.113883.10.20.1.53' &quot;MP-templateId&quot;;\n medication -&gt; manufacturedProduct.manufacturedMaterial as manufacturedMaterial then ManufacturedMaterialEntryContentModulePrescription(bundle, medicationRequest, medication, manufacturedMaterial, substanceAdministration) &quot;manufacturedMaterial&quot;;\n };\n // TODO: AUTHOR1 Medication Treatment Plan Author\n medicationRequest where dosageInstruction.count() = 1 then {\n medicationRequest.dosageInstruction as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-nonstructured') -&gt; substanceAdministration.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.5.3.1.4.7.1' &quot;normalDose&quot;;\n } &quot;onylonedosage&quot;;\n medicationRequest.dosageInstruction as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-normal-medicationrequest') then DosageInstructionsStartStopFrequencySubstanceAdministration(dosage, substanceAdministration) &quot;DosageSubstanceAdministration&quot;;\n // dosage for split dosing (with sequences): effectiveTime (start/stop) &amp; routeCode\n medicationRequest.dosageInstruction first as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split-medicationrequest') -&gt; substanceAdministration.entryRelationship as entryRelationship then DosageInstructionsEntryStartStopRoute(dosage, substanceAdministration, entryRelationship) &quot;DosageSubstanceAdministration&quot;;\n // dosage for split dosing (with sequences): sequence number, effectiveTime (when), dose quantity, consumable\n medicationRequest.dosageInstruction as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split-medicationrequest') -&gt; substanceAdministration.entryRelationship as entryRelationship, entryRelationship.typeCode = 'COMP' then DosageInstructionsEntryDosageChangeSubstanceAdministration(dosage, substanceAdministration, entryRelationship) &quot;DosageSubstanceAdministration&quot;;\n medicationRequest.reasonCode as reasonCode -&gt; substanceAdministration.entryRelationship as entryRelationship, entryRelationship.typeCode = 'RSON', entryRelationship.observation as observation then TreatmentReasonEntryContentModule(reasonCode, observation) &quot;TreatmentReasonEntryContentModule&quot;;\n medicationRequest.extension as extension where url = 'http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-ext-treatmentplan' -&gt; substanceAdministration.entryRelationship as entryRelationship, entryRelationship.typeCode = 'REFR', entryRelationship.substanceAdministration as substanceAdministration then MTPReferenceEntryContentModule(extension, substanceAdministration) &quot;MTP-Reference&quot;;\n // TODO: Patient Medication Instructions Contains 1.3.6.1.4.1.19376.1.5.3.1.4.3 IHE Patient Medication Instructions (DYNAMIC)\n medicationRequest.dosageInstruction as dosage where $this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-nonstructured') -&gt; substanceAdministration.entryRelationship as entryRelationship, entryRelationship.typeCode = 'COMP', entryRelationship.substanceAdministration as substanceAdministration then DosageInstructionsNonStructuredEntryContentModule(dosage, substanceAdministration) &quot;DosageInstructionsNonStructuredEntryContentModule&quot;;\n medicationRequest.note as note -&gt; substanceAdministration.entryRelationship as entryRelationship, entryRelationship.typeCode = 'COMP', entryRelationship.act as act then AnnotationComment(note, act) &quot;AnnotationComment&quot;;\n medicationRequest.substitution as substitution -&gt; substanceAdministration.entryRelationship as entryRelationship, entryRelationship.typeCode = 'COMP', entryRelationship.act as act then SubstitutionRequest(substitution, act) &quot;Substitution&quot;;\n}\n\n// source: http://build.fhir.org/ig/hl7ch/ch-emed/StructureDefinition-ch-emed-observation.html\n// target: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&amp;id=2.16.756.5.30.1.1.10.4.44\ngroup PharmaceuticalAdviceItemEntryContentModule(source bundle : Bundle, source fhirobservation : Observation, target cdaobservation : Observation) {\n fhirobservation -&gt; cdaobservation.classCode = 'OBS' &quot;OBS&quot;;\n fhirobservation -&gt; cdaobservation.moodCode = 'EVN' &quot;EVN&quot;;\n fhirobservation -&gt; cdaobservation.templateId as templateId, templateId.root = '1.3.6.1.4.1.19376.1.9.1.3.3' &quot;IHE-PHARM-PADV&quot;;\n fhirobservation -&gt; cdaobservation.templateId as templateId, templateId.root = '2.16.756.5.30.1.1.10.4.44' &quot;CH-PHARM-PharmaceuticalAdviceItemEntryContentModule&quot;;\n fhirobservation.identifier as identifier -&gt; cdaobservation.id as id then IdentifierII(identifier, id) &quot;id&quot;;\n fhirobservation.code as fhirCode -&gt; cdaobservation.code as cdaCode then CodeableConceptCE(fhirCode, cdaCode);\n fhirobservation -&gt; cdaobservation.statusCode as statusCode, statusCode.code = 'completed' &quot;code&quot;;\n fhirobservation.effectiveDateTime as effectiveDateTime -&gt; cdaobservation.effectiveTime as effectiveTime then {\n effectiveDateTime -&gt; effectiveTime.value = effectiveDateTime &quot;value&quot;;\n } &quot;effectiveTime&quot;;\n fhirobservation.extension as extension where url = 'http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-ext-treatmentplan' -&gt; cdaobservation.entryRelationship as entryRelationship, entryRelationship.typeCode = 'REFR', entryRelationship.substanceAdministration as substanceAdministration then MTPReferenceEntryContentModule(extension, substanceAdministration) &quot;MTP-Reference&quot;;\n fhirobservation.extension as extension where url = 'http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-ext-medicationstatement-changed' -&gt; cdaobservation.entryRelationship as entryRelationship, entryRelationship.typeCode = 'REFR' then {\n bundle.entry as entry then {\n entry.fullUrl where ($this in %extension.valueReference.reference) and $this.startsWith('urn:uuid') then {\n entry.resource as medicationStatement where $this.ofType(FHIR.MedicationStatement) -&gt; entryRelationship.substanceAdministration as substanceAdministration then MedicationTreatmentPlanItemEntryContentModule(bundle, medicationStatement, substanceAdministration) &quot;MedicationStatement&quot;;\n } &quot;fullUrlAsUuid&quot;;\n entry.resource as medicationStatement where $this.ofType(FHIR.MedicationStatement) and (('MedicationStatement' + '/' + $this.id) in %extension.valueReference.reference) -&gt; entryRelationship.substanceAdministration as substanceAdministration then MedicationTreatmentPlanItemEntryContentModule(bundle, medicationStatement, substanceAdministration) &quot;MedicationStatement&quot;;\n };\n } &quot;changedmtp&quot;;\n fhirobservation.note as note then {\n note.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' -&gt; cdaobservation.text as text, text.reference as reference then {\n extension.valueUrl as valueUrl -&gt; reference.value = valueUrl;\n } &quot;narrativeLink&quot;;\n note where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) -&gt; cdaobservation.text as text, text.reference as reference, reference.value = '#refpdf' &quot;reference&quot;;\n };\n fhirobservation.note as note -&gt; cdaobservation.text as text then {\n note.text as noteText -&gt; text.data = noteText;\n note.extension as extension where $this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink' then {\n extension.valueUrl as valueUrl -&gt; text.reference as reference, reference.value = valueUrl &quot;reference&quot;;\n } &quot;id&quot;;\n note where (extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false) -&gt; text.reference as reference, reference.value = '#refpdf' &quot;reference&quot;;\n } &quot;text&quot;;\n}\n\n</pre>\n </div>"
  },
  "url" : "http://fhir.ch/ig/cda-fhir-maps/StructureMap/BundleToCdaChEmed",
  "version" : "0.3.0",
  "name" : "BundleToCdaChEmed",
  "status" : "draft",
  "date" : "2022-02-11T11:14:39+01:00",
  "publisher" : "ahdis",
  "contact" : [
    {
      "name" : "ahdis",
      "telecom" : [
        {
          "system" : "url",
          "value" : "http://www.ahdis.ch/"
        }
      ]
    }
  ],
  "description" : "\r\nMedication Entries\r\n2020-11-11 Michaela Ziegler, copyright ahdis ag, Apache License\r\nCDA-CH-EMED: https://art-decor.org/art-decor/decor-project--cdachemed-\r\nFHIR CH-EMED: http://fhir.ch/ig/ch-emed/index.html\r\n",
  "copyright" : "CC-BY-SA-4.0",
  "structure" : [
    {
      "url" : "http://hl7.org/fhir/cda/StructureDefinition/ClinicalDocument",
      "mode" : "target",
      "alias" : "ClinicalDocument"
    },
    {
      "url" : "http://hl7.org/fhir/cda/StructureDefinition/AssignedAuthor",
      "mode" : "target",
      "alias" : "AssignedAuthor"
    },
    {
      "url" : "http://hl7.org/fhir/cda/StructureDefinition/AssignedEntity",
      "mode" : "target",
      "alias" : "AssignedEntity"
    },
    {
      "url" : "http://hl7.org/fhir/cda/StructureDefinition/Author",
      "mode" : "target",
      "alias" : "Author"
    },
    {
      "url" : "http://hl7.org/fhir/cda/StructureDefinition/CustodianOrganization",
      "mode" : "target",
      "alias" : "CustodianOrganization"
    },
    {
      "url" : "http://hl7.org/fhir/cda/StructureDefinition/IVL_TS",
      "mode" : "target",
      "alias" : "IVL_TS"
    },
    {
      "url" : "http://hl7.org/fhir/cda/StructureDefinition/EIVL_TS",
      "mode" : "target",
      "alias" : "EIVL_TS"
    },
    {
      "url" : "http://hl7.org/fhir/cda/StructureDefinition/PatientRole",
      "mode" : "target",
      "alias" : "PatientRole"
    },
    {
      "url" : "http://hl7.org/fhir/cda/StructureDefinition/RecordTarget",
      "mode" : "target",
      "alias" : "RecordTarget"
    },
    {
      "url" : "http://hl7.org/fhir/cda/StructureDefinition/Section",
      "mode" : "target",
      "alias" : "Section"
    },
    {
      "url" : "http://hl7.org/fhir/cda/StructureDefinition/SubstanceAdministration",
      "mode" : "target",
      "alias" : "SubstanceAdministration"
    },
    {
      "url" : "http://hl7.org/fhir/cda/StructureDefinition/SXPR_TS",
      "mode" : "target",
      "alias" : "SXPR_TS"
    },
    {
      "url" : "http://hl7.org/fhir/cda/StructureDefinition/Supply",
      "mode" : "target",
      "alias" : "Supply"
    },
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/Bundle",
      "mode" : "source",
      "alias" : "Bundle"
    },
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/Composition",
      "mode" : "source",
      "alias" : "Composition"
    },
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/Patient",
      "mode" : "source",
      "alias" : "Patient"
    },
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/Practitioner",
      "mode" : "source",
      "alias" : "Practitioner"
    },
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/Organization",
      "mode" : "source",
      "alias" : "Organization"
    },
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/MedicationStatement",
      "mode" : "source",
      "alias" : "MedicationStatement"
    },
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/Dosage",
      "mode" : "source",
      "alias" : "Dosage"
    }
  ],
  "import" : [
    "http://fhir.ch/ig/cda-fhir-maps/StructureMap/FhirToCdaTypes",
    "http://fhir.ch/ig/cda-fhir-maps/StructureMap/BundleToCda",
    "http://fhir.ch/ig/cda-fhir-maps/StructureMap/BundleToCdaCh"
  ],
  "group" : [
    {
      "name" : "AnnotationComment",
      "typeMode" : "none",
      "documentation" : "source: Annotation note (e.g. http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationstatement.html)\r\ntarget: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.4.2",
      "input" : [
        {
          "name" : "note",
          "type" : "Annotation",
          "mode" : "source"
        },
        {
          "name" : "act",
          "type" : "Act",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "ACT",
          "source" : [
            {
              "context" : "note"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "ACT"
                }
              ]
            }
          ]
        },
        {
          "name" : "EVN",
          "source" : [
            {
              "context" : "note"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "moodCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "EVN"
                }
              ]
            }
          ]
        },
        {
          "name" : "templateId",
          "source" : [
            {
              "context" : "note"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "2.16.756.5.30.1.1.10.4.2"
                }
              ]
            }
          ]
        },
        {
          "name" : "templateId",
          "source" : [
            {
              "context" : "note"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "2.16.840.1.113883.10.20.1.40"
                }
              ]
            }
          ]
        },
        {
          "name" : "templateId",
          "source" : [
            {
              "context" : "note"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.5.3.1.4.2"
                }
              ]
            }
          ]
        },
        {
          "name" : "code",
          "source" : [
            {
              "context" : "note"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "code",
              "variable" : "code"
            },
            {
              "context" : "code",
              "contextType" : "variable",
              "element" : "code",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "48767-8"
                }
              ]
            },
            {
              "context" : "code",
              "contextType" : "variable",
              "element" : "codeSystem",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "2.16.840.1.113883.6.1"
                }
              ]
            },
            {
              "context" : "code",
              "contextType" : "variable",
              "element" : "displayName",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "Annotation comment"
                }
              ]
            },
            {
              "context" : "code",
              "contextType" : "variable",
              "element" : "codeSystemName",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "LOINC"
                }
              ]
            }
          ]
        },
        {
          "name" : "text",
          "source" : [
            {
              "context" : "note",
              "element" : "text",
              "variable" : "noteText"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "text",
              "variable" : "text"
            }
          ],
          "rule" : [
            {
              "name" : "text",
              "source" : [
                {
                  "context" : "noteText"
                }
              ],
              "target" : [
                {
                  "context" : "text",
                  "contextType" : "variable",
                  "element" : "data",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "noteText"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "id",
              "source" : [
                {
                  "context" : "note",
                  "element" : "extension",
                  "variable" : "extension",
                  "condition" : "$this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink'"
                }
              ],
              "rule" : [
                {
                  "name" : "reference",
                  "source" : [
                    {
                      "context" : "extension",
                      "element" : "valueUrl",
                      "variable" : "valueUrl"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "text",
                      "contextType" : "variable",
                      "element" : "reference",
                      "variable" : "reference"
                    },
                    {
                      "context" : "reference",
                      "contextType" : "variable",
                      "element" : "value",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueId" : "valueUrl"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name" : "reference",
              "source" : [
                {
                  "context" : "note",
                  "condition" : "(extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false)"
                }
              ],
              "target" : [
                {
                  "context" : "text",
                  "contextType" : "variable",
                  "element" : "reference",
                  "variable" : "reference"
                },
                {
                  "context" : "reference",
                  "contextType" : "variable",
                  "element" : "value",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "#refpdf"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "statusCode",
          "source" : [
            {
              "context" : "note"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "statusCode",
              "variable" : "code"
            },
            {
              "context" : "code",
              "contextType" : "variable",
              "element" : "code",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "completed"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "ManufacturedMaterialEntryContentModuleStatement",
      "typeMode" : "none",
      "documentation" : "source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationstatement.html\r\ntarget: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.4.33&effectiveDate=2019-12-11T11:34:24&language=en-US",
      "input" : [
        {
          "name" : "bundle",
          "type" : "Bundle",
          "mode" : "source"
        },
        {
          "name" : "medicationStatement",
          "type" : "MedicationStatement",
          "mode" : "source"
        },
        {
          "name" : "medication",
          "type" : "Medication",
          "mode" : "source"
        },
        {
          "name" : "manufacturedMaterial",
          "type" : "ManufacturedMaterial",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "MMAT",
          "source" : [
            {
              "context" : "medication"
            }
          ],
          "target" : [
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "MMAT"
                }
              ]
            }
          ]
        },
        {
          "name" : "KIND",
          "source" : [
            {
              "context" : "medication"
            }
          ],
          "target" : [
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "determinerCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "KIND"
                }
              ]
            }
          ]
        },
        {
          "name" : "CH-PHARM-ManufacturedMaterialContentModule",
          "source" : [
            {
              "context" : "medication"
            }
          ],
          "target" : [
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "2.16.756.5.30.1.1.10.4.33"
                }
              ]
            }
          ]
        },
        {
          "name" : "templateId",
          "source" : [
            {
              "context" : "medication"
            }
          ],
          "target" : [
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.9.1.3.1"
                }
              ]
            }
          ]
        },
        {
          "name" : "name",
          "source" : [
            {
              "context" : "medication",
              "element" : "code",
              "variable" : "code"
            }
          ],
          "rule" : [
            {
              "name" : "brandname",
              "source" : [
                {
                  "context" : "code",
                  "element" : "text",
                  "variable" : "text"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedMaterial",
                  "contextType" : "variable",
                  "element" : "name",
                  "variable" : "name"
                },
                {
                  "context" : "name",
                  "contextType" : "variable",
                  "element" : "other",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "text"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "code",
          "source" : [
            {
              "context" : "medication",
              "element" : "code",
              "variable" : "code"
            }
          ],
          "rule" : [
            {
              "name" : "id",
              "source" : [
                {
                  "context" : "code",
                  "element" : "extension",
                  "variable" : "extension",
                  "condition" : "$this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink'"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedMaterial",
                  "contextType" : "variable",
                  "element" : "code",
                  "variable" : "code"
                }
              ],
              "rule" : [
                {
                  "name" : "reference",
                  "source" : [
                    {
                      "context" : "extension",
                      "element" : "valueUrl",
                      "variable" : "valueUrl"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "code",
                      "contextType" : "variable",
                      "element" : "originalText",
                      "variable" : "text"
                    },
                    {
                      "context" : "text",
                      "contextType" : "variable",
                      "element" : "reference",
                      "variable" : "reference"
                    },
                    {
                      "context" : "reference",
                      "contextType" : "variable",
                      "element" : "value",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueId" : "valueUrl"
                        }
                      ]
                    }
                  ]
                }
              ],
              "documentation" : "#mtpc.no.brandedmedication"
            },
            {
              "name" : "reference",
              "source" : [
                {
                  "context" : "code",
                  "condition" : "(extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false)"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedMaterial",
                  "contextType" : "variable",
                  "element" : "code",
                  "variable" : "code"
                },
                {
                  "context" : "code",
                  "contextType" : "variable",
                  "element" : "originalText",
                  "variable" : "text"
                },
                {
                  "context" : "text",
                  "contextType" : "variable",
                  "element" : "reference",
                  "variable" : "reference"
                },
                {
                  "context" : "reference",
                  "contextType" : "variable",
                  "element" : "value",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "#refpdf"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "code",
              "source" : [
                {
                  "context" : "code",
                  "element" : "coding",
                  "variable" : "coding"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedMaterial",
                  "contextType" : "variable",
                  "element" : "code",
                  "variable" : "ce"
                }
              ],
              "dependent" : [
                {
                  "name" : "CodingCE",
                  "variable" : [
                    "coding",
                    "ce"
                  ]
                }
              ]
            },
            {
              "name" : "nullFlavor",
              "source" : [
                {
                  "context" : "code",
                  "condition" : "coding.exists() = false"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedMaterial",
                  "contextType" : "variable",
                  "element" : "code",
                  "variable" : "ce"
                },
                {
                  "context" : "ce",
                  "contextType" : "variable",
                  "element" : "nullFlavor",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "NA"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "form",
          "source" : [
            {
              "context" : "medication",
              "element" : "form",
              "variable" : "form"
            }
          ],
          "rule" : [
            {
              "name" : "formCode",
              "source" : [
                {
                  "context" : "form",
                  "element" : "coding",
                  "variable" : "coding"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedMaterial",
                  "contextType" : "variable",
                  "element" : "formCode",
                  "variable" : "formCode"
                }
              ],
              "dependent" : [
                {
                  "name" : "CodingCE",
                  "variable" : [
                    "coding",
                    "formCode"
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "code",
          "source" : [
            {
              "context" : "medication",
              "element" : "code",
              "variable" : "code"
            }
          ],
          "target" : [
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "asContent",
              "variable" : "asContent"
            },
            {
              "context" : "asContent",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "CONT"
                }
              ]
            },
            {
              "context" : "asContent",
              "contextType" : "variable",
              "element" : "containerPackagedMedicine",
              "variable" : "containerPackagedMedicine"
            }
          ],
          "rule" : [
            {
              "name" : "CONT",
              "source" : [
                {
                  "context" : "code"
                }
              ],
              "target" : [
                {
                  "context" : "containerPackagedMedicine",
                  "contextType" : "variable",
                  "element" : "classCode",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "CONT"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "INSTANCE",
              "source" : [
                {
                  "context" : "code"
                }
              ],
              "target" : [
                {
                  "context" : "containerPackagedMedicine",
                  "contextType" : "variable",
                  "element" : "determinerCode",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "INSTANCE"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "pharm-code",
              "source" : [
                {
                  "context" : "code",
                  "element" : "coding",
                  "variable" : "coding"
                }
              ],
              "target" : [
                {
                  "context" : "containerPackagedMedicine",
                  "contextType" : "variable",
                  "element" : "code",
                  "variable" : "ce"
                }
              ],
              "dependent" : [
                {
                  "name" : "CodingCE",
                  "variable" : [
                    "coding",
                    "ce"
                  ]
                }
              ]
            },
            {
              "name" : "pharm-name",
              "source" : [
                {
                  "context" : "code",
                  "element" : "text",
                  "variable" : "text"
                }
              ],
              "target" : [
                {
                  "context" : "containerPackagedMedicine",
                  "contextType" : "variable",
                  "element" : "name",
                  "variable" : "name"
                },
                {
                  "context" : "name",
                  "contextType" : "variable",
                  "element" : "other",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "text"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "form",
              "source" : [
                {
                  "context" : "medication",
                  "element" : "form",
                  "variable" : "form"
                }
              ],
              "rule" : [
                {
                  "name" : "pharm-formCode",
                  "source" : [
                    {
                      "context" : "form",
                      "element" : "coding",
                      "variable" : "coding"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "containerPackagedMedicine",
                      "contextType" : "variable",
                      "element" : "formCode",
                      "variable" : "formCode"
                    }
                  ],
                  "dependent" : [
                    {
                      "name" : "CodingCE",
                      "variable" : [
                        "coding",
                        "formCode"
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name" : "amount",
              "source" : [
                {
                  "context" : "medication",
                  "element" : "amount",
                  "variable" : "amount"
                }
              ],
              "rule" : [
                {
                  "name" : "numerator",
                  "source" : [
                    {
                      "context" : "amount",
                      "element" : "numerator",
                      "variable" : "numerator"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "containerPackagedMedicine",
                      "contextType" : "variable",
                      "element" : "capacityQuantity",
                      "variable" : "capacityQuantity"
                    }
                  ],
                  "rule" : [
                    {
                      "name" : "value",
                      "source" : [
                        {
                          "context" : "numerator",
                          "element" : "value",
                          "variable" : "value"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "capacityQuantity",
                          "contextType" : "variable",
                          "element" : "value",
                          "transform" : "copy",
                          "parameter" : [
                            {
                              "valueId" : "value"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name" : "unit",
                      "source" : [
                        {
                          "context" : "numerator",
                          "element" : "code",
                          "variable" : "unit"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "capacityQuantity",
                          "contextType" : "variable",
                          "element" : "unit",
                          "transform" : "copy",
                          "parameter" : [
                            {
                              "valueId" : "unit"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ],
              "documentation" : "Package size"
            }
          ]
        },
        {
          "name" : "ingredient",
          "source" : [
            {
              "context" : "medication",
              "element" : "ingredient",
              "variable" : "ingredient"
            }
          ],
          "target" : [
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "ingredient",
              "variable" : "ingredient"
            },
            {
              "context" : "ingredient",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "ACTI"
                }
              ]
            }
          ],
          "rule" : [
            {
              "name" : "PharmSubstance",
              "source" : [
                {
                  "context" : "ingredient",
                  "element" : "itemCodeableConcept",
                  "variable" : "itemCodeableConcept"
                }
              ],
              "target" : [
                {
                  "context" : "ingredient",
                  "contextType" : "variable",
                  "element" : "ingredient",
                  "variable" : "pharmsubstance"
                }
              ],
              "rule" : [
                {
                  "name" : "MMAT",
                  "source" : [
                    {
                      "context" : "itemCodeableConcept"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "pharmsubstance",
                      "contextType" : "variable",
                      "element" : "classCode",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueString" : "MMAT"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name" : "KIND",
                  "source" : [
                    {
                      "context" : "itemCodeableConcept"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "pharmsubstance",
                      "contextType" : "variable",
                      "element" : "determinerCode",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueString" : "KIND"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name" : "name",
                  "source" : [
                    {
                      "context" : "itemCodeableConcept",
                      "element" : "text",
                      "variable" : "text"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "pharmsubstance",
                      "contextType" : "variable",
                      "element" : "name",
                      "variable" : "name"
                    },
                    {
                      "context" : "name",
                      "contextType" : "variable",
                      "element" : "other",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueId" : "text"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name" : "coding",
                  "source" : [
                    {
                      "context" : "itemCodeableConcept",
                      "element" : "coding",
                      "variable" : "coding"
                    }
                  ],
                  "rule" : [
                    {
                      "name" : "formCode",
                      "source" : [
                        {
                          "context" : "coding"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "pharmsubstance",
                          "contextType" : "variable",
                          "element" : "code",
                          "variable" : "ce"
                        }
                      ],
                      "dependent" : [
                        {
                          "name" : "CodingCE",
                          "variable" : [
                            "coding",
                            "ce"
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name" : "strength",
              "source" : [
                {
                  "context" : "ingredient",
                  "element" : "strength",
                  "variable" : "strength"
                }
              ],
              "target" : [
                {
                  "context" : "ingredient",
                  "contextType" : "variable",
                  "element" : "quantity",
                  "variable" : "quantity"
                }
              ],
              "dependent" : [
                {
                  "name" : "RatioRTOPQPQ",
                  "variable" : [
                    "strength",
                    "quantity"
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "MedicationTreatmentPlanItemEntryContentModule",
      "typeMode" : "none",
      "documentation" : "source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationstatement.html\r\ntarget: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.4.34&effectiveDate=2019-12-11T11:31:52&language=en-US",
      "input" : [
        {
          "name" : "bundle",
          "type" : "Bundle",
          "mode" : "source"
        },
        {
          "name" : "medicationStatement",
          "type" : "MedicationStatement",
          "mode" : "source"
        },
        {
          "name" : "substanceAdministration",
          "type" : "SubstanceAdministration",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "SBADM",
          "source" : [
            {
              "context" : "medicationStatement"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "SBADM"
                }
              ]
            }
          ]
        },
        {
          "name" : "INT",
          "source" : [
            {
              "context" : "medicationStatement"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "moodCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "INT"
                }
              ]
            }
          ]
        },
        {
          "name" : "CH-PHARM-MedicationTreatmentPlanItemEntryContentModule",
          "source" : [
            {
              "context" : "medicationStatement"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "2.16.756.5.30.1.1.10.4.34"
                }
              ]
            }
          ]
        },
        {
          "name" : "IHE-PHARM-MTP",
          "source" : [
            {
              "context" : "medicationStatement"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.9.1.3.7"
                }
              ]
            }
          ]
        },
        {
          "name" : "CCD",
          "source" : [
            {
              "context" : "medicationStatement"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "2.16.840.1.113883.10.20.1.24"
                }
              ]
            }
          ]
        },
        {
          "name" : "PCC-MedicationEntryContentModule",
          "source" : [
            {
              "context" : "medicationStatement"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.5.3.1.4.7"
                }
              ]
            }
          ]
        },
        {
          "name" : "id",
          "source" : [
            {
              "context" : "medicationStatement",
              "element" : "identifier",
              "variable" : "identifier"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
&nbs       {
          "name" : "entry",
          "type" : "entryRelationship",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "splitDose",
          "source" : [
            {
              "context" : "dosage"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
               {
              "name" : "id",
              "source" : [
                {
                  "context" : "extension",
                  "element" : "valueIdentifier",
                  "variable" : "valueIdentifier"
                }
              ],
              "target" : [
                {
                  "context" : "substanceAdministration",
                  "contextType" : "variable",
                  "element" : "reference",
                  "variable" : "reference"
                },
                {
                  "context" : "reference",
                  "contextType" : "variable",
                  "element" : "typeCode",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "XCRPT"
                    }
                  ]
                },
                {
                  "context" : "reference",
                  "contextType" : "variable",
                  "element" : "externalDocument",
                  "variable" : "externalDocument"
                },
                {
                  "context" : "externalDocument",
                  "contextType" : "variable",
                  "element" : "id",
                  "variable" : "id"
                }
              ],
              "dependent" : [
                {
                  "name" : "IdentifierII",
                  "variable" : [
                    "valueIdentifier",
                    "id"
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "DosageInstructionsNonStructuredEntryContentModule",
      "typeMode" : "none",
      "documentation" : "source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-dosage-nonstructured.html\r\ntarget: https://art-decor.org/art-decor/decor-templates--ch-pharm-?section=templates&id=2.16.756.5.30.1.1.10.4.52\r\nDosage Instruction (Statement, Prescription)",
      "input" : [
        {
          "name" : "dosage",
          "type" : "Dosage",
          "mode" : "source"
        },
        {
          "name" : "substanceAdministration",
          "type" : "SubstanceAdministration",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "SBADM",
          "source" : [
            {
              "context" : "dosage"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "SBADM"
                }
              ]
            }
          ]
        },
        {
          "name" : "INT",
          "source" : [
            {
              "context" : "dosage"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "moodCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "INT"
                }
              ]
            }
          ]
        },
        {
          "name" : "templateId",
          "source" : [
            {
              "context" : "dosage"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "2.16.756.5.30.1.1.10.4.52"
                }
              ]
            }
          ]
        },
        {
          "name" : "text",
          "source" : [
            {
              "context" : "dosage",
              "element" : "text",
              "variable" : "noteText"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "text",
              "variable" : "text"
            }
          ],
          "rule" : [
            {
              "name" : "text",
              "source" : [
                {
                  "context" : "noteText"
                }
              ],
              "target" : [
                {
                  "context" : "text",
                  "contextType" : "variable",
                  "element" : "data",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "noteText"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "id",
              "source" : [
                {
                  "context" : "dosage",
                  "element" : "extension",
                  "variable" : "extension",
                  "condition" : "$this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink'"
                }
              ],
              "rule" : [
                {
                  "name" : "reference",
                  "source" : [
                    {
                      "context" : "extension",
                      "element" : "valueUrl",
                      "variable" : "valueUrl"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "text",
                      "contextType" : "variable",
                      "element" : "reference",
                      "variable" : "reference"
                    },
                    {
                      "context" : "reference",
                      "contextType" : "variable",
                      "element" : "value",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueId" : "valueUrl"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name" : "reference",
              "source" : [
                {
                  "context" : "dosage",
                  "condition" : "(extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false)"
                }
              ],
              "target" : [
                {
                  "context" : "text",
                  "contextType" : "variable",
                  "element" : "reference",
                  "variable" : "reference"
                },
                {
                  "context" : "reference",
                  "contextType" : "variable",
                  "element" : "value",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "#refpdf"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "consumable",
          "source" : [
            {
              "context" : "dosage"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "consumable",
              "variable" : "consumable"
            },
            {
              "context" : "consumable",
              "contextType" : "variable",
              "element" : "manufacturedProduct",
              "variable" : "manufacturedProduct"
            },
            {
              "context" : "manufacturedProduct",
              "contextType" : "variable",
              "element" : "manufacturedMaterial",
              "variable" : "manufacturedMaterial"
            },
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "nullFlavor",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "NA"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "SubstitutionDispense",
      "typeMode" : "none",
      "documentation" : "source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationdispense.html\r\ntarget: Substitution act Contains 1.3.6.1.4.1.19376.1.9.1.3.9.2 IHE Substitution Act Content Module\r\nSubstitution (Dispense)",
      "input" : [
        {
          "name" : "substitution",
          "type" : "Substitution",
          "mode" : "source"
        },
        {
          "name" : "act",
          "type" : "Act",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "ACT",
          "source" : [
            {
              "context" : "substitution"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "ACT"
                }
              ]
            }
          ]
        },
        {
          "name" : "EVN",
          "source" : [
            {
              "context" : "substitution"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "moodCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "EVN"
                }
              ]
            }
          ]
        },
        {
          "name" : "templateId",
          "source" : [
            {
              "context" : "substitution"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.9.1.3.9.2"
                }
              ]
            }
          ]
        },
        {
          "name" : "substitution",
          "source" : [
            {
              "context" : "substitution",
              "element" : "type",
              "variable" : "type"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "code",
              "variable" : "code"
            }
          ],
          "dependent" : [
            {
              "name" : "CodeableConceptCE",
              "variable" : [
                "type",
                "code"
              ]
            }
          ]
        },
        {
          "name" : "statusCode",
          "source" : [
            {
              "context" : "substitution"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "statusCode",
              "variable" : "statusCode"
            },
            {
              "context" : "statusCode",
              "contextType" : "variable",
              "element" : "code",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "completed"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "ManufacturedMaterialEntryContentModuleDispense",
      "typeMode" : "none",
      "documentation" : "source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationdispense.html\r\ntarget: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.4.33&effectiveDate=2019-12-11T11:34:24&language=en-US",
      "input" : [
        {
          "name" : "bundle",
          "type" : "Bundle",
          "mode" : "source"
        },
        {
          "name" : "medicationDispense",
          "type" : "MedicationDispense",
          "mode" : "source"
        },
        {
          "name" : "medication",
          "type" : "Medication",
          "mode" : "source"
        },
        {
          "name" : "manufacturedMaterial",
          "type" : "ManufacturedMaterial",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "MMAT",
          "source" : [
            {
              "context" : "medication"
            }
          ],
          "target" : [
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "MMAT"
                }
              ]
            }
          ]
        },
        {
          "name" : "KIND",
          "source" : [
            {
              "context" : "medication"
            }
          ],
          "target" : [
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "determinerCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "KIND"
                }
              ]
            }
          ]
        },
        {
          "name" : "CH-PHARM-ManufacturedMaterialContentModule",
          "source" : [
            {
              "context" : "medication"
            }
          ],
          "target" : [
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "2.16.756.5.30.1.1.10.4.33"
                }
              ]
            }
          ]
        },
        {
          "name" : "templateId",
          "source" : [
            {
              "context" : "medication"
            }
          ],
          "target" : [
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.9.1.3.1"
                }
              ]
            }
          ]
        },
        {
          "name" : "name",
          "source" : [
            {
              "context" : "medication",
              "element" : "code",
              "variable" : "code"
            }
          ],
          "rule" : [
            {
              "name" : "brandname",
              "source" : [
                {
                  "context" : "code",
                  "element" : "text",
                  "variable" : "text"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedMaterial",
                  "contextType" : "variable",
                  "element" : "name",
                  "variable" : "name"
                },
                {
                  "context" : "name",
                  "contextType" : "variable",
                  "element" : "other",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "text"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "code",
          "source" : [
            {
              "context" : "medication",
              "element" : "code",
              "variable" : "code"
            }
          ],
          "rule" : [
            {
              "name" : "id",
              "source" : [
                {
                  "context" : "code",
                  "element" : "extension",
                  "variable" : "extension",
                  "condition" : "$this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink'"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedMaterial",
                  "contextType" : "variable",
                  "element" : "code",
                  "variable" : "code"
                }
              ],
              "rule" : [
                {
                  "name" : "reference",
                  "source" : [
                    {
                      "context" : "extension",
                      "element" : "valueUrl",
                      "variable" : "valueUrl"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "code",
                      "contextType" : "variable",
                      "element" : "originalText",
                      "variable" : "text"
                    },
                    {
                      "context" : "text",
                      "contextType" : "variable",
                      "element" : "reference",
                      "variable" : "reference"
                    },
                    {
                      "context" : "reference",
                      "contextType" : "variable",
                      "element" : "value",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueId" : "valueUrl"
                        }
                      ]
                    }
                  ]
                }
              ],
              "documentation" : "#dis.no.brandedmedication"
            },
            {
              "name" : "reference",
              "source" : [
                {
                  "context" : "code",
                  "condition" : "(extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false)"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedMaterial",
                  "contextType" : "variable",
                  "element" : "code",
                  "variable" : "code"
                },
                {
                  "context" : "code",
                  "contextType" : "variable",
                  "element" : "originalText",
                  "variable" : "text"
                },
                {
                  "context" : "text",
                  "contextType" : "variable",
                  "element" : "reference",
                  "variable" : "reference"
                },
                {
                  "context" : "reference",
                  "contextType" : "variable",
                  "element" : "value",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "#refpdf"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "code",
              "source" : [
                {
                  "context" : "code",
                  "element" : "coding",
                  "variable" : "coding"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedMaterial",
                  "contextType" : "variable",
                  "element" : "code",
                  "variable" : "ce"
                }
              ],
              "dependent" : [
                {
                  "name" : "CodingCE",
                  "variable" : [
                    "coding",
                    "ce"
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "form",
          "source" : [
            {
              "context" : "medication",
              "element" : "form",
              "variable" : "form"
            }
          ],
          "rule" : [
            {
              "name" : "formCode",
              "source" : [
                {
                  "context" : "form",
                  "element" : "coding",
                  "variable" : "coding"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedMaterial",
                  "contextType" : "variable",
                  "element" : "formCode",
                  "variable" : "formCode"
                }
              ],
              "dependent" : [
                {
                  "name" : "CodingCE",
                  "variable" : [
                    "coding",
                    "formCode"
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "code",
          "source" : [
            {
              "context" : "medication",
              "element" : "code",
              "variable" : "code"
            }
          ],
          "target" : [
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "asContent",
              "variable" : "asContent"
            },
            {
              "context" : "asContent",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "CONT"
                }
              ]
            },
            {
              "context" : "asContent",
              "contextType" : "variable",
              "element" : "containerPackagedMedicine",
              "variable" : "containerPackagedMedicine"
            }
          ],
          "rule" : [
            {
              "name" : "CONT",
              "source" : [
                {
                  "context" : "code"
                }
              ],
              "target" : [
                {
                  "context" : "containerPackagedMedicine",
                  "contextType" : "variable",
                  "element" : "classCode",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "CONT"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "INSTANCE",
              "source" : [
                {
                  "context" : "code"
                }
              ],
              "target" : [
                {
                  "context" : "containerPackagedMedicine",
                  "contextType" : "variable",
                  "element" : "determinerCode",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "INSTANCE"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "pharm-code",
              "source" : [
                {
                  "context" : "code",
                  "element" : "coding",
                  "variable" : "coding"
                }
              ],
              "target" : [
                {
                  "context" : "containerPackagedMedicine",
                  "contextType" : "variable",
                  "element" : "code",
                  "variable" : "ce"
                }
              ],
              "dependent" : [
                {
                  "name" : "CodingCE",
                  "variable" : [
                    "coding",
                    "ce"
                  ]
                }
              ]
            },
            {
              "name" : "pharm-name",
              "source" : [
                {
                  "context" : "code",
                  "element" : "text",
                  "variable" : "text"
                }
              ],
              "target" : [
                {
                  "context" : "containerPackagedMedicine",
                  "contextType" : "variable",
                  "element" : "name",
                  "variable" : "name"
                },
                {
                  "context" : "name",
                  "contextType" : "variable",
                  "element" : "other",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "text"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "form",
              "source" : [
                {
                  "context" : "medication",
                  "element" : "form",
                  "variable" : "form"
                }
              ],
              "rule" : [
                {
                  "name" : "pharm-formCode",
                  "source" : [
                    {
                      "context" : "form",
                      "element" : "coding",
                      "variable" : "coding"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "containerPackagedMedicine",
                      "contextType" : "variable",
                      "element" : "formCode",
                      "variable" : "formCode"
                    }
                  ],
                  "dependent" : [
                    {
                      "name" : "CodingCE",
                      "variable" : [
                        "coding",
                        "formCode"
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name" : "amount",
              "source" : [
                {
                  "context" : "medication",
                  "element" : "amount",
                  "variable" : "amount"
                }
              ],
              "rule" : [
                {
                  "name" : "numerator",
                  "source" : [
                    {
                      "context" : "amount",
                      "element" : "numerator",
                      "variable" : "numerator"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "containerPackagedMedicine",
                      "contextType" : "variable",
                      "element" : "capacityQuantity",
                      "variable" : "capacityQuantity"
                    }
                  ],
                  "rule" : [
                    {
                      "name" : "value",
                      "source" : [
                        {
                          "context" : "numerator",
                          "element" : "value",
                          "variable" : "value"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "capacityQuantity",
                          "contextType" : "variable",
                          "element" : "value",
                          "transform" : "copy",
                          "parameter" : [
                            {
                              "valueId" : "value"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name" : "unit",
                      "source" : [
                        {
                          "context" : "numerator",
                          "element" : "code",
                          "variable" : "unit"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "capacityQuantity",
                          "contextType" : "variable",
                          "element" : "unit",
                          "transform" : "copy",
                          "parameter" : [
                            {
                              "valueId" : "unit"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ],
              "documentation" : "Package size"
            }
          ]
        },
        {
          "name" : "ingredient",
          "source" : [
            {
              "context" : "medication",
              "element" : "ingredient",
              "variable" : "ingredient"
            }
          ],
          "target" : [
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "ingredient",
              "variable" : "ingredient"
            },
            {
              "context" : "ingredient",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "ACTI"
                }
              ]
            }
          ],
          "rule" : [
            {
              "name" : "PharmSubstance",
              "source" : [
                {
                  "context" : "ingredient",
                  "element" : "itemCodeableConcept",
                  "variable" : "itemCodeableConcept"
                }
              ],
              "target" : [
                {
                  "context" : "ingredient",
                  "contextType" : "variable",
                  "element" : "ingredient",
                  "variable" : "pharmsubstance"
                }
              ],
              "rule" : [
                {
                  "name" : "MMAT",
                  "source" : [
                    {
                      "context" : "itemCodeableConcept"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "pharmsubstance",
                      "contextType" : "variable",
                      "element" : "classCode",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueString" : "MMAT"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name" : "KIND",
                  "source" : [
                    {
                      "context" : "itemCodeableConcept"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "pharmsubstance",
                      "contextType" : "variable",
                      "element" : "determinerCode",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueString" : "KIND"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name" : "name",
                  "source" : [
                    {
                      "context" : "itemCodeableConcept",
                      "element" : "text",
                      "variable" : "text"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "pharmsubstance",
                      "contextType" : "variable",
                      "element" : "name",
                      "variable" : "name"
                    },
                    {
                      "context" : "name",
                      "contextType" : "variable",
                      "element" : "other",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueId" : "text"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name" : "coding",
                  "source" : [
                    {
                      "context" : "itemCodeableConcept",
                      "element" : "coding",
                      "variable" : "coding"
                    }
                  ],
                  "rule" : [
                    {
                      "name" : "formCode",
                      "source" : [
                        {
                          "context" : "coding"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "pharmsubstance",
                          "contextType" : "variable",
                          "element" : "code",
                          "variable" : "ce"
                        }
                      ],
                      "dependent" : [
                        {
                          "name" : "CodingCE",
                          "variable" : [
                            "coding",
                            "ce"
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name" : "strength",
              "source" : [
                {
                  "context" : "ingredient",
                  "element" : "strength",
                  "variable" : "strength"
                }
              ],
              "target" : [
                {
                  "context" : "ingredient",
                  "contextType" : "variable",
                  "element" : "quantity",
                  "variable" : "quantity"
                }
              ],
              "dependent" : [
                {
                  "name" : "RatioRTOPQPQ",
                  "variable" : [
                    "strength",
                    "quantity"
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "DispenseItemEntryContentModule",
      "typeMode" : "none",
      "documentation" : "source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationdispense.html\r\ntarget: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.4.42",
      "input" : [
        {
          "name" : "bundle",
          "type" : "Bundle",
          "mode" : "source"
        },
        {
          "name" : "medicationDispense",
          "type" : "MedicationDispense",
          "mode" : "source"
        },
        {
          "name" : "supply",
          "type" : "Supply",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "SPLY",
          "source" : [
            {
              "context" : "medicationDispense"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "SPLY"
                }
              ]
            }
          ]
        },
        {
          "name" : "EVN",
          "source" : [
            {
              "context" : "medicationDispense"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "moodCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "EVN"
                }
              ]
            }
          ]
        },
        {
          "name" : "CH-PHARM-DispenseItemEntryContentModule",
          "source" : [
            {
              "context" : "medicationDispense"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "2.16.756.5.30.1.1.10.4.42"
                }
              ]
            }
          ]
        },
        {
          "name" : "IHE-PHARM-DIS",
          "source" : [
            {
              "context" : "medicationDispense"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.9.1.3.4"
                }
              ]
            }
          ]
        },
        {
          "name" : "supplyEntry",
          "source" : [
            {
              "context" : "medicationDispense"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.5.3.1.4.7.3"
                }
              ]
            }
          ]
        },
        {
          "name" : "CCD",
          "source" : [
            {
              "context" : "medicationDispense"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "2.16.840.1.113883.10.20.1.34"
                }
              ]
            }
          ]
        },
        {
          "name" : "id",
          "source" : [
            {
              "context" : "medicationDispense",
              "element" : "identifier",
              "variable" : "identifier"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "id",
              "variable" : "id"
            }
          ],
          "dependent" : [
            {
              "name" : "IdentifierII",
              "variable" : [
                "identifier",
                "id"
              ]
            }
          ]
        },
        {
          "name" : "narrativeLink",
          "source" : [
            {
              "context" : "medicationDispense",
              "element" : "extension",
              "variable" : "extension",
              "condition" : "$this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink'"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "text",
              "variable" : "text"
            },
            {
              "context" : "text",
              "contextType" : "variable",
              "element" : "reference",
              "variable" : "reference"
            }
          ],
          "rule" : [
            {
              "name" : "valueUrl",
              "source" : [
                {
                  "context" : "extension",
                  "element" : "valueUrl",
                  "variable" : "valueUrl"
                }
              ],
              "target" : [
                {
                  "context" : "reference",
                  "contextType" : "variable",
                  "element" : "value",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "valueUrl"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "reference",
          "source" : [
            {
              "context" : "medicationDispense",
              "condition" : "(extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false)"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "text",
              "variable" : "text"
            },
            {
              "context" : "text",
              "contextType" : "variable",
              "element" : "reference",
              "variable" : "reference"
            },
            {
              "context" : "text",
              "contextType" : "variable",
              "element" : "reference",
              "variable" : "reference"
            },
            {
              "context" : "reference",
              "contextType" : "variable",
              "element" : "value",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "#refpdf"
                }
              ]
            }
          ]
        },
        {
          "name" : "contained",
          "source" : [
            {
              "context" : "medicationDispense",
              "element" : "contained",
              "variable" : "medication",
              "condition" : "('#' + $this.id) in %medicationDispense.medicationReference.reference"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "product",
              "variable" : "product"
            },
            {
              "context" : "product",
              "contextType" : "variable",
              "element" : "manufacturedProduct",
              "variable" : "manufacturedProduct"
            },
            {
              "context" : "manufacturedProduct",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "MANU"
                }
              ]
            }
          ],
          "rule" : [
            {
              "name" : "MP-TemplateId",
              "source" : [
                {
                  "context" : "medication"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedProduct",
                  "contextType" : "variable",
                  "element" : "templateId",
                  "variable" : "templateId"
                },
                {
                  "context" : "templateId",
                  "contextType" : "variable",
                  "element" : "root",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "1.3.6.1.4.1.19376.1.5.3.1.4.7.2"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "MP-TemplateId",
              "source" : [
                {
                  "context" : "medication"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedProduct",
                  "contextType" : "variable",
                  "element" : "templateId",
                  "variable" : "templateId"
                },
                {
                  "context" : "templateId",
                  "contextType" : "variable",
                  "element" : "root",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "2.16.840.1.113883.10.20.1.53"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "manufacturedMaterial",
              "source" : [
                {
                  "context" : "medication"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedProduct",
                  "contextType" : "variable",
                  "element" : "manufacturedMaterial",
                  "variable" : "manufacturedMaterial"
                }
              ],
              "dependent" : [
                {
                  "name" : "ManufacturedMaterialEntryContentModuleDispense",
                  "variable" : [
                    "bundle",
                    "medicationDispense",
                    "medication",
                    "manufacturedMaterial"
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "MTP-Reference",
          "source" : [
            {
              "context" : "medicationDispense",
              "element" : "extension",
              "variable" : "extension",
              "condition" : "url = 'http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-ext-treatmentplan'"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "entryRelationship",
              "variable" : "entryRelationship"
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "typeCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "REFR"
                }
              ]
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "substanceAdministration",
              "variable" : "substanceAdministration"
            }
          ],
          "dependent" : [
            {
              "name" : "MTPReferenceEntryContentModule",
              "variable" : [
                "extension",
                "substanceAdministration"
              ]
            }
          ],
          "documentation" : "TODO: AUTHOR1 Medication Treatment Plan Author"
        },
        {
          "name" : "onylonedosage",
          "source" : [
            {
              "context" : "medicationDispense",
              "condition" : "dosageInstruction.count() = 1"
            }
          ],
          "rule" : [
            {
              "name" : "normalDose",
              "source" : [
                {
                  "context" : "medicationDispense",
                  "element" : "dosageInstruction",
                  "variable" : "dosage",
                  "condition" : "$this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-nonstructured')"
                }
              ],
              "target" : [
                {
                  "context" : "substanceAdministration",
                  "contextType" : "variable",
                  "element" : "templateId",
                  "variable" : "templateId"
                },
                {
                  "context" : "templateId",
                  "contextType" : "variable",
                  "element" : "root",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "1.3.6.1.4.1.19376.1.5.3.1.4.7.1"
                    }
                  ]
                }
              ]
            }
          ],
          "documentation" : "#24 missing template it if ch-emed-dosage-nonstructured"
        },
        {
          "name" : "DosageSubstanceAdministration",
          "source" : [
            {
              "context" : "medicationDispense",
              "element" : "dosageInstruction",
              "variable" : "dosage",
              "condition" : "$this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-normal')"
            }
          ],
          "dependent" : [
            {
              "name" : "DosageInstructionsStartStopFrequencySupply",
              "variable" : [
                "dosage",
                "supply"
              ]
            }
          ],
          "documentation" : "dosage for normal dosing, as no sequences are present there"
        },
        {
          "name" : "entryRelationship",
          "source" : [
            {
              "context" : "medicationDispense"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "entryRelationship",
              "variable" : "entryRelationship"
            }
          ],
          "rule" : [
            {
              "name" : "substanceAdministration",
              "source" : [
                {
                  "context" : "medicationDispense"
                }
              ],
              "target" : [
                {
                  "context" : "entryRelationship",
                  "contextType" : "variable",
                  "element" : "substanceAdministration",
                  "variable" : "substanceAdministration"
                }
              ],
              "rule" : [
                {
                  "name" : "DosageSubstanceAdministration",
                  "source" : [
                    {
                      "context" : "medicationDispense",
                      "element" : "dosageInstruction",
                      "listMode" : "first",
                      "variable" : "dosage",
                      "condition" : "$this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split')"
                    }
                  ],
                  "target" : [
                    {
                      "contextType" : "variable",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueId" : "substanceAdministration"
                        }
                      ]
                    }
                  ],
                  "dependent" : [
                    {
                      "name" : "DosageInstructionsEntryStartStopRouteConsumable",
                      "variable" : [
                        "dosage",
                        "entryRelationship",
                        "substanceAdministration"
                      ]
                    }
                  ],
                  "documentation" : "split dosing (with sequences): effectiveTime (start/stop) & routeCode & consumable"
                },
                {
                  "name" : "DosageSubstanceAdministration",
                  "source" : [
                    {
                      "context" : "medicationDispense",
                      "element" : "dosageInstruction",
                      "variable" : "dosage",
                      "condition" : "$this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split')"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "substanceAdministration",
                      "contextType" : "variable",
                      "element" : "entryRelationship",
                      "variable" : "entryRelationship"
                    },
                    {
                      "context" : "entryRelationship",
                      "contextType" : "variable",
                      "element" : "typeCode",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueString" : "COMP"
                        }
                      ]
                    }
                  ],
                  "dependent" : [
                    {
                      "name" : "DosageInstructionsEntryDosageChangeEntryRelationship",
                      "variable" : [
                        "dosage",
                        "entryRelationship"
                      ]
                    }
                  ],
                  "documentation" : "split dosing (with sequences): sequence number, effectiveTime (when), dose quantity, consumable"
                }
              ]
            }
          ],
          "documentation" : "dosage for split dosing, as sequences are present there"
        },
        {
          "name" : "DosageInstructionsNonStructuredEntryContentModule",
          "source" : [
            {
              "context" : "medicationDispense",
              "element" : "dosageInstruction",
              "variable" : "dosage",
              "condition" : "$this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-nonstructured')"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "entryRelationship",
              "variable" : "entryRelationship"
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "typeCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "COMP"
                }
              ]
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "substanceAdministration",
              "variable" : "substanceAdministration"
            }
          ],
          "dependent" : [
            {
              "name" : "DosageInstructionsNonStructuredEntryContentModule",
              "variable" : [
                "dosage",
                "substanceAdministration"
              ]
            }
          ],
          "documentation" : "TODO: Precondition Criterion"
        },
        {
          "name" : "quantity",
          "source" : [
            {
              "context" : "medicationDispense",
              "element" : "quantity",
              "variable" : "quantity"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "quantity",
              "variable" : "supplyQuantity"
            }
          ],
          "rule" : [
            {
              "name" : "value",
              "source" : [
                {
                  "context" : "quantity",
                  "element" : "value",
                  "variable" : "value"
                }
              ],
              "target" : [
                {
                  "context" : "supplyQuantity",
                  "contextType" : "variable",
                  "element" : "value",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "value"
                    }
                  ]
                }
              ]
            }
          ],
          "documentation" : "Number of packages"
        },
        {
          "name" : "AnnotationComment",
          "source" : [
            {
              "context" : "medicationDispense",
              "element" : "note",
              "variable" : "note"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "entryRelationship",
              "variable" : "entryRelationship"
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "typeCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "COMP"
                }
              ]
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "act",
              "variable" : "act"
            }
          ],
          "dependent" : [
            {
              "name" : "AnnotationComment",
              "variable" : [
                "note",
                "act"
              ]
            }
          ]
        },
        {
          "name" : "Substitution",
          "source" : [
            {
              "context" : "medicationDispense",
              "element" : "substitution",
              "variable" : "substitution"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "entryRelationship",
              "variable" : "entryRelationship"
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "typeCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "COMP"
                }
              ]
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "act",
              "variable" : "act"
            }
          ],
          "dependent" : [
            {
              "name" : "SubstitutionDispense",
              "variable" : [
                "substitution",
                "act"
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "DosageInstructionsStartStopFrequencySupply",
      "typeMode" : "none",
      "documentation" : "source: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-normal\r\ntarget: https://art-decor.org/art-decor/decor-templates--ch-pharm-?id=2.16.756.5.30.1.1.10.4.35\r\ndosage for normal dosing (without sequences) (Dispense)",
      "input" : [
        {
          "name" : "dosage",
          "type" : "Dosage",
          "mode" : "source"
        },
        {
          "name" : "supply",
          "type" : "Supply",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "entryRelationship",
          "source" : [
            {
              "context" : "dosage"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "entryRelationship",
              "variable" : "entryRelationship"
            }
          ],
          "rule" : [
            {
              "name" : "COMP",
              "source" : [
                {
                  "context" : "dosage"
                }
              ],
              "target" : [
                {
                  "context" : "entryRelationship",
                  "contextType" : "variable",
                  "element" : "typeCode",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "COMP"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "substanceAdministration",
              "source" : [
                {
                  "context" : "dosage"
                }
              ],
              "target" : [
                {
                  "context" : "entryRelationship",
                  "contextType" : "variable",
                  "element" : "substanceAdministration",
                  "variable" : "substanceAdministration"
                }
              ],
              "rule" : [
                {
                  "name" : "SBADM",
                  "source" : [
                    {
                      "context" : "dosage"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "substanceAdministration",
                      "contextType" : "variable",
                      "element" : "classCode",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueString" : "SBADM"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name" : "INT",
                  "source" : [
                    {
                      "context" : "dosage"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "substanceAdministration",
                      "contextType" : "variable",
                      "element" : "moodCode",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueString" : "INT"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name" : "templateId",
                  "source" : [
                    {
                      "context" : "dosage"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "substanceAdministration",
                      "contextType" : "variable",
                      "element" : "templateId",
                      "variable" : "templateId"
                    },
                    {
                      "context" : "templateId",
                      "contextType" : "variable",
                      "element" : "root",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueString" : "1.3.6.1.4.1.19376.1.9.1.3.6"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name" : "normalDose",
                  "source" : [
                    {
                      "context" : "dosage"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "substanceAdministration",
                      "contextType" : "variable",
                      "element" : "templateId",
                      "variable" : "templateId"
                    },
                    {
                      "context" : "templateId",
                      "contextType" : "variable",
                      "element" : "root",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueString" : "1.3.6.1.4.1.19376.1.5.3.1.4.7.1"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name" : "effectiveTimeStartEnd",
                  "source" : [
                    {
                      "context" : "dosage"
                    }
                  ],
                  "target" : [
                    {
                      "contextType" : "variable",
                      "variable" : "substanceAdministration",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueId" : "substanceAdministration"
                        }
                      ]
                    }
                  ],
                  "dependent" : [
                    {
                      "name" : "EffectiveTimeStartEnd",
                      "variable" : [
                        "dosage",
                        "substanceAdministration"
                      ]
                    }
                  ]
                },
                {
                  "name" : "effectiveTimeWhen",
                  "source" : [
                    {
                      "context" : "dosage"
                    }
                  ],
                  "target" : [
                    {
                      "contextType" : "variable",
                      "variable" : "substanceAdministration",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueId" : "substanceAdministration"
                        }
                      ]
                    }
                  ],
                  "dependent" : [
                    {
                      "name" : "EffectiveTimeWhenNormal",
                      "variable" : [
                        "dosage",
                        "substanceAdministration"
                      ]
                    }
                  ]
                },
                {
                  "name" : "route",
                  "source" : [
                    {
                      "context" : "dosage",
                      "element" : "route",
                      "variable" : "route"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "substanceAdministration",
                      "contextType" : "variable",
                      "element" : "routeCode",
                      "variable" : "routeCode"
                    }
                  ],
                  "dependent" : [
                    {
                      "name" : "CodeableConceptCE",
                      "variable" : [
                        "route",
                        "routeCode"
                      ]
                    }
                  ]
                },
                {
                  "name" : "doseQuantity",
                  "source" : [
                    {
                      "context" : "dosage"
                    }
                  ],
                  "target" : [
                    {
                      "contextType" : "variable",
                      "variable" : "substanceAdministration",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueId" : "substanceAdministration"
                        }
                      ]
                    }
                  ],
                  "dependent" : [
                    {
                      "name" : "DoseQuantity",
                      "variable" : [
                        "dosage",
                        "substanceAdministration"
                      ]
                    }
                  ]
                },
                {
                  "name" : "consumable",
                  "source" : [
                    {
                      "context" : "dosage"
                    }
                  ],
                  "target" : [
                    {
                      "contextType" : "variable",
                      "variable" : "substanceAdministration",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueId" : "substanceAdministration"
                        }
                      ]
                    },
                    {
                      "context" : "substanceAdministration",
                      "contextType" : "variable",
                      "element" : "consumable",
                      "variable" : "consumable"
                    },
                    {
                      "context" : "consumable",
                      "contextType" : "variable",
                      "element" : "manufacturedProduct",
                      "variable" : "manufacturedProduct"
                    },
                    {
                      "context" : "manufacturedProduct",
                      "contextType" : "variable",
                      "element" : "manufacturedMaterial",
                      "variable" : "manufacturedMaterial"
                    },
                    {
                      "context" : "manufacturedMaterial",
                      "contextType" : "variable",
                      "element" : "nullFlavor",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueString" : "NA"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "DosageInstructionsEntryStartStopRouteConsumable",
      "typeMode" : "none",
      "documentation" : "source: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split\r\ntarget: https://art-decor.org/art-decor/decor-templates--ch-pharm-?id=2.16.756.5.30.1.1.10.4.36\r\ndosage for split dosing: effectiveTime (start/stop) & routeCode & consumable (Dispense)",
      "input" : [
        {
          "name" : "dosage",
          "type" : "Dosage",
          "mode" : "source"
        },
        {
          "name" : "entryRelationship",
          "type" : "entryRelationship",
          "mode" : "target"
        },
        {
          "name" : "substanceAdministration",
          "type" : "SubstanceAdministration",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "COMP",
          "source" : [
            {
              "context" : "dosage"
            }
          ],
          "target" : [
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "typeCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "COMP"
                }
              ]
            }
          ]
        },
        {
          "name" : "SBADM",
          "source" : [
            {
              "context" : "dosage"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "SBADM"
                }
              ]
            }
          ]
        },
        {
          "name" : "INT",
          "source" : [
            {
              "context" : "dosage"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "moodCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "INT"
                }
              ]
            }
          ]
        },
        {
          "name" : "templateId",
          "source" : [
            {
              "context" : "dosage"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.9.1.3.6"
                }
              ]
            }
          ]
        },
        {
          "name" : "splitDose",
          "source" : [
            {
              "context" : "dosage"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.5.3.1.4.9"
                }
              ]
            }
          ]
        },
        {
          "name" : "effectiveTimeStartEnd",
          "source" : [
            {
              "context" : "dosage"
            }
          ],
          "target" : [
            {
              "contextType" : "variable",
              "variable" : "substanceAdministration",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueId" : "substanceAdministration"
                }
              ]
            }
          ],
          "dependent" : [
            {
              "name" : "EffectiveTimeStartEnd",
              "variable" : [
                "dosage",
                "substanceAdministration"
              ]
            }
          ]
        },
        {
          "name" : "route",
          "source" : [
            {
              "context" : "dosage",
              "element" : "route",
              "variable" : "route"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "routeCode",
              "variable" : "routeCode"
            }
          ],
          "dependent" : [
            {
              "name" : "CodeableConceptCE",
              "variable" : [
                "route",
                "routeCode"
              ]
            }
          ]
        },
        {
          "name" : "consumable",
          "source" : [
            {
              "context" : "dosage"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "consumable",
              "variable" : "consumable"
            },
            {
              "context" : "consumable",
              "contextType" : "variable",
              "element" : "manufacturedProduct",
              "variable" : "manufacturedProduct"
            },
            {
              "context" : "manufacturedProduct",
              "contextType" : "variable",
              "element" : "manufacturedMaterial",
              "variable" : "manufacturedMaterial"
            },
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "nullFlavor",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "NA"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "DosageInstructionsEntryDosageChangeEntryRelationship",
      "typeMode" : "none",
      "documentation" : "source: http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split\r\ntarget: https://art-decor.org/art-decor/decor-templates--ch-pharm-?id=2.16.756.5.30.1.1.10.4.36\r\ndosage for split dosing: sequence number, effectiveTime (when), dose quantity, consumable (Dispense)",
      "input" : [
        {
          "name" : "dosage",
          "type" : "Dosage",
          "mode" : "source"
        },
        {
          "name" : "entryRelationship",
          "type" : "entryRelationship",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "sequence",
          "source" : [
            {
              "context" : "dosage",
              "element" : "sequence",
              "variable" : "sequence"
            }
          ],
          "target" : [
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "sequenceNumber",
              "variable" : "sequenceNumber"
            },
            {
              "context" : "sequenceNumber",
              "contextType" : "variable",
              "element" : "value",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueId" : "sequence"
                }
              ]
            }
          ]
        },
        {
          "name" : "dosage",
          "source" : [
            {
              "context" : "dosage"
            }
          ],
          "target" : [
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "substanceAdministration",
              "variable" : "substanceAdministration"
            },
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "SBADM"
                }
              ]
            },
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "moodCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "INT"
                }
              ]
            }
          ],
          "rule" : [
            {
              "name" : "effectiveTimeWhen",
              "source" : [
                {
                  "context" : "dosage",
                  "variable" : "dosage"
                }
              ],
              "target" : [
                {
                  "contextType" : "variable",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "substanceAdministration"
                    }
                  ]
                }
              ],
              "dependent" : [
                {
                  "name" : "EffectiveTimeWhenSplit",
                  "variable" : [
                    "dosage",
                    "substanceAdministration"
                  ]
                }
              ]
            },
            {
              "name" : "doseQuantity",
              "source" : [
                {
                  "context" : "dosage",
                  "variable" : "dosage"
                }
              ],
              "target" : [
                {
                  "contextType" : "variable",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "substanceAdministration"
                    }
                  ]
                }
              ],
              "dependent" : [
                {
                  "name" : "DoseQuantity",
                  "variable" : [
                    "dosage",
                    "substanceAdministration"
                  ]
                }
              ]
            },
            {
              "name" : "consumable",
              "source" : [
                {
                  "context" : "dosage",
                  "variable" : "dosage"
                }
              ],
              "target" : [
                {
                  "context" : "substanceAdministration",
                  "contextType" : "variable",
                  "element" : "consumable",
                  "variable" : "consumable"
                },
                {
                  "context" : "consumable",
                  "contextType" : "variable",
                  "element" : "manufacturedProduct",
                  "variable" : "manufacturedProduct"
                },
                {
                  "context" : "manufacturedProduct",
                  "contextType" : "variable",
                  "element" : "manufacturedMaterial",
                  "variable" : "manufacturedMaterial"
                },
                {
                  "context" : "manufacturedMaterial",
                  "contextType" : "variable",
                  "element" : "nullFlavor",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "NA"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "EffectiveTimeWhenNormal",
      "typeMode" : "none",
      "documentation" : "effective time when for normal dosage (Dispense, Statement, Prescription)",
      "input" : [
        {
          "name" : "dosage",
          "type" : "Dosage",
          "mode" : "source"
        },
        {
          "name" : "substanceAdministration",
          "type" : "SubstanceAdministration",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "timing",
          "source" : [
            {
              "context" : "dosage",
              "element" : "timing",
              "variable" : "timing"
            }
          ],
          "rule" : [
            {
              "name" : "repeat",
              "source" : [
                {
                  "context" : "timing",
                  "element" : "repeat",
                  "variable" : "repeat"
                }
              ],
              "rule" : [
                {
                  "name" : "when",
                  "source" : [
                    {
                      "context" : "repeat",
                      "condition" : "$this.when.count() = 1"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "substanceAdministration",
                      "contextType" : "variable",
                      "element" : "effectiveTime",
                      "variable" : "effectiveTime",
                      "transform" : "create",
                      "parameter" : [
                        {
                          "valueString" : "EIVL_TS"
                        }
                      ]
                    },
                    {
                      "context" : "effectiveTime",
                      "contextType" : "variable",
                      "element" : "operator",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueString" : "A"
                        }
                      ]
                    }
                  ],
                  "rule" : [
                    {
                      "name" : "when",
                      "source" : [
                        {
                          "context" : "repeat",
                          "element" : "when",
                          "variable" : "when"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "effectiveTime",
                          "contextType" : "variable",
                          "element" : "event",
                          "variable" : "event"
                        },
                        {
                          "context" : "event",
                          "contextType" : "variable",
                          "element" : "code",
                          "transform" : "copy",
                          "parameter" : [
                            {
                              "valueId" : "when"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name" : "when",
                  "source" : [
                    {
                      "context" : "repeat",
                      "condition" : "$this.when.count() > 1"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "substanceAdministration",
                      "contextType" : "variable",
                      "element" : "effectiveTime",
                      "variable" : "effectiveTime",
                      "transform" : "create",
                      "parameter" : [
                        {
                          "valueString" : "SXPR_TS"
                        }
                      ]
                    },
                    {
                      "context" : "effectiveTime",
                      "contextType" : "variable",
                      "element" : "operator",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueString" : "A"
                        }
                      ]
                    }
                  ],
                  "rule" : [
                    {
                      "name" : "comp",
                      "source" : [
                        {
                          "context" : "repeat",
                          "element" : "when",
                          "listMode" : "first",
                          "variable" : "when"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "effectiveTime",
                          "contextType" : "variable",
                          "element" : "comp",
                          "variable" : "comp",
                          "transform" : "create",
                          "parameter" : [
                            {
                              "valueString" : "EIVL_TS"
                            }
                          ]
                        }
                      ],
                      "rule" : [
                        {
                          "name" : "when",
                          "source" : [
                            {
                              "context" : "when"
                            }
                          ],
                          "target" : [
                            {
                              "context" : "comp",
                              "contextType" : "variable",
                              "element" : "event",
                              "variable" : "event"
                            },
                            {
                              "context" : "event",
                              "contextType" : "variable",
                              "element" : "code",
                              "transform" : "copy",
                              "parameter" : [
                                {
                                  "valueId" : "when"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name" : "compnotfirst",
                      "source" : [
                        {
                          "context" : "repeat",
                          "element" : "when",
                          "listMode" : "not_first",
                          "variable" : "when"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "effectiveTime",
                          "contextType" : "variable",
                          "element" : "comp",
                          "variable" : "comp",
                          "transform" : "create",
                          "parameter" : [
                            {
                              "valueString" : "EIVL_TS"
                            }
                          ]
                        },
                        {
                          "context" : "comp",
                          "contextType" : "variable",
                          "element" : "operator",
                          "transform" : "copy",
                          "parameter" : [
                            {
                              "valueString" : "I"
                            }
                          ]
                        }
                      ],
                      "rule" : [
                        {
                          "name" : "when",
                          "source" : [
                            {
                              "context" : "when"
                            }
                          ],
                          "target" : [
                            {
                              "context" : "comp",
                              "contextType" : "variable",
                              "element" : "event",
                              "variable" : "event"
                            },
                            {
                              "context" : "event",
                              "contextType" : "variable",
                              "element" : "code",
                              "transform" : "copy",
                              "parameter" : [
                                {
                                  "valueId" : "when"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "EffectiveTimeWhenSplit",
      "typeMode" : "none",
      "documentation" : "effective time when for split dosage (Dispense, Statement, Prescription)",
      "input" : [
        {
          "name" : "dosage",
          "type" : "Dosage",
          "mode" : "source"
        },
        {
          "name" : "substanceAdministration",
          "type" : "SubstanceAdministration",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "timing",
          "source" : [
            {
              "context" : "dosage",
              "element" : "timing",
              "variable" : "timing"
            }
          ],
          "rule" : [
            {
              "name" : "repeat",
              "source" : [
                {
                  "context" : "timing",
                  "element" : "repeat",
                  "variable" : "repeat"
                }
              ],
              "rule" : [
                {
                  "name" : "when",
                  "source" : [
                    {
                      "context" : "repeat",
                      "condition" : "$this.when.count() = 1"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "substanceAdministration",
                      "contextType" : "variable",
                      "element" : "effectiveTime",
                      "variable" : "effectiveTime",
                      "transform" : "create",
                      "parameter" : [
                        {
                          "valueString" : "EIVL_TS"
                        }
                      ]
                    }
                  ],
                  "rule" : [
                    {
                      "name" : "when",
                      "source" : [
                        {
                          "context" : "repeat",
                          "element" : "when",
                          "variable" : "when"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "effectiveTime",
                          "contextType" : "variable",
                          "element" : "event",
                          "variable" : "event"
                        },
                        {
                          "context" : "event",
                          "contextType" : "variable",
                          "element" : "code",
                          "transform" : "copy",
                          "parameter" : [
                            {
                              "valueId" : "when"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name" : "when",
                  "source" : [
                    {
                      "context" : "repeat",
                      "condition" : "$this.when.count() > 1"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "substanceAdministration",
                      "contextType" : "variable",
                      "element" : "effectiveTime",
                      "variable" : "effectiveTime",
                      "transform" : "create",
                      "parameter" : [
                        {
                          "valueString" : "SXPR_TS"
                        }
                      ]
                    },
                    {
                      "context" : "effectiveTime",
                      "contextType" : "variable",
                      "element" : "operator",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueString" : "A"
                        }
                      ]
                    }
                  ],
                  "rule" : [
                    {
                      "name" : "comp",
                      "source" : [
                        {
                          "context" : "repeat",
                          "element" : "when",
                          "listMode" : "first",
                          "variable" : "when"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "effectiveTime",
                          "contextType" : "variable",
                          "element" : "comp",
                          "variable" : "comp",
                          "transform" : "create",
                          "parameter" : [
                            {
                              "valueString" : "EIVL_TS"
                            }
                          ]
                        }
                      ],
                      "rule" : [
                        {
                          "name" : "when",
                          "source" : [
                            {
                              "context" : "when"
                            }
                          ],
                          "target" : [
                            {
                              "context" : "comp",
                              "contextType" : "variable",
                              "element" : "event",
                              "variable" : "event"
                            },
                            {
                              "context" : "event",
                              "contextType" : "variable",
                              "element" : "code",
                              "transform" : "copy",
                              "parameter" : [
                                {
                                  "valueId" : "when"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name" : "compnotfirst",
                      "source" : [
                        {
                          "context" : "repeat",
                          "element" : "when",
                          "listMode" : "not_first",
                          "variable" : "when"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "effectiveTime",
                          "contextType" : "variable",
                          "element" : "comp",
                          "variable" : "comp",
                          "transform" : "create",
                          "parameter" : [
                            {
                              "valueString" : "EIVL_TS"
                            }
                          ]
                        },
                        {
                          "context" : "comp",
                          "contextType" : "variable",
                          "element" : "operator",
                          "transform" : "copy",
                          "parameter" : [
                            {
                              "valueString" : "I"
                            }
                          ]
                        }
                      ],
                      "rule" : [
                        {
                          "name" : "when",
                          "source" : [
                            {
                              "context" : "when"
                            }
                          ],
                          "target" : [
                            {
                              "context" : "comp",
                              "contextType" : "variable",
                              "element" : "event",
                              "variable" : "event"
                            },
                            {
                              "context" : "event",
                              "contextType" : "variable",
                              "element" : "code",
                              "transform" : "copy",
                              "parameter" : [
                                {
                                  "valueId" : "when"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "SubstitutionRequest",
      "typeMode" : "none",
      "documentation" : "source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationrequest.html\r\ntarget: Substitution permission Contains 1.3.6.1.4.1.19376.1.9.1.3.9.1 IHE Substitution Permission Content Module",
      "input" : [
        {
          "name" : "substitution",
          "type" : "Substitution",
          "mode" : "source"
        },
        {
          "name" : "act",
          "type" : "Act",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "ACT",
          "source" : [
            {
              "context" : "substitution"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "ACT"
                }
              ]
            }
          ]
        },
        {
          "name" : "DEF",
          "source" : [
            {
              "context" : "substitution"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "moodCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "DEF"
                }
              ]
            }
          ]
        },
        {
          "name" : "templateId",
          "source" : [
            {
              "context" : "substitution"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.9.1.3.9.1"
                }
              ]
            }
          ]
        },
        {
          "name" : "substitution",
          "source" : [
            {
              "context" : "substitution",
              "element" : "allowedCodeableConcept",
              "variable" : "allowedCC"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "code",
              "variable" : "code"
            }
          ],
          "dependent" : [
            {
              "name" : "CodeableConceptCE",
              "variable" : [
                "allowedCC",
                "code"
              ]
            }
          ]
        },
        {
          "name" : "statusCode",
          "source" : [
            {
              "context" : "substitution"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "statusCode",
              "variable" : "statusCode"
            },
            {
              "context" : "statusCode",
              "contextType" : "variable",
              "element" : "code",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "completed"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "SubstitutionStatement",
      "typeMode" : "none",
      "documentation" : "source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationrequest.html\r\ntarget: Substitution permission Contains 1.3.6.1.4.1.19376.1.9.1.3.9.1 IHE Substitution Permission Content Module",
      "input" : [
        {
          "name" : "extension",
          "type" : "Extension",
          "mode" : "source"
        },
        {
          "name" : "act",
          "type" : "Act",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "ACT",
          "source" : [
            {
              "context" : "extension"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "ACT"
                }
              ]
            }
          ]
        },
        {
          "name" : "DEF",
          "source" : [
            {
              "context" : "extension"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "moodCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "DEF"
                }
              ]
            }
          ]
        },
        {
          "name" : "templateId",
          "source" : [
            {
              "context" : "extension"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.9.1.3.9.1"
                }
              ]
            }
          ]
        },
        {
          "name" : "extension",
          "source" : [
            {
              "context" : "extension",
              "element" : "valueCodeableConcept",
              "variable" : "valueCC"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "code",
              "variable" : "code"
            }
          ],
          "dependent" : [
            {
              "name" : "CodeableConceptCE",
              "variable" : [
                "valueCC",
                "code"
              ]
            }
          ]
        },
        {
          "name" : "statusCode",
          "source" : [
            {
              "context" : "extension"
            }
          ],
          "target" : [
            {
              "context" : "act",
              "contextType" : "variable",
              "element" : "statusCode",
              "variable" : "statusCode"
            },
            {
              "context" : "statusCode",
              "contextType" : "variable",
              "element" : "code",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "completed"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "PrescribedQuantity",
      "typeMode" : "none",
      "documentation" : "source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationrequest.html\r\ntarget: https://art-decor.org/art-decor/decor-templates--cdachemed-?id=2.16.756.5.30.1.1.10.4.38",
      "input" : [
        {
          "name" : "dispenseRequest",
          "type" : "DispenseRequest",
          "mode" : "source"
        },
        {
          "name" : "supply",
          "type" : "Supply",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "SPLY",
          "source" : [
            {
              "context" : "dispenseRequest"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "SPLY"
                }
              ]
            }
          ]
        },
        {
          "name" : "RQO",
          "source" : [
            {
              "context" : "dispenseRequest"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "moodCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "RQO"
                }
              ]
            }
          ]
        },
        {
          "name" : "templateId",
          "source" : [
            {
              "context" : "dispenseRequest"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.9.1.3.8"
                }
              ]
            }
          ]
        },
        {
          "name" : "independentInd",
          "source" : [
            {
              "context" : "dispenseRequest"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "independentInd",
              "variable" : "independentInd"
            },
            {
              "context" : "independentInd",
              "contextType" : "variable",
              "element" : "value",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "false"
                }
              ]
            }
          ]
        },
        {
          "name" : "quantity",
          "source" : [
            {
              "context" : "dispenseRequest",
              "element" : "quantity",
              "variable" : "quantity"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "quantity",
              "variable" : "quant"
            }
          ],
          "rule" : [
            {
              "name" : "value",
              "source" : [
                {
                  "context" : "quantity",
                  "element" : "value",
                  "variable" : "value"
                }
              ],
              "target" : [
                {
                  "context" : "quant",
                  "contextType" : "variable",
                  "element" : "value",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "value"
                    }
                  ]
                }
              ]
            }
          ],
          "documentation" : "Number of packages"
        }
      ]
    },
    {
      "name" : "PrescribedQuantityUnit",
      "typeMode" : "none",
      "documentation" : "source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationrequest.html\r\ntarget: https://art-decor.org/art-decor/decor-templates--cdachemed-?id=2.16.756.5.30.1.1.10.4.38",
      "input" : [
        {
          "name" : "dispenseRequest",
          "type" : "DispenseRequest",
          "mode" : "source"
        },
        {
          "name" : "supply",
          "type" : "Supply",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "SPLY",
          "source" : [
            {
              "context" : "dispenseRequest"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "SPLY"
                }
              ]
            }
          ]
        },
        {
          "name" : "RQO",
          "source" : [
            {
              "context" : "dispenseRequest"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "moodCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "RQO"
                }
              ]
            }
          ]
        },
        {
          "name" : "TemplateId",
          "source" : [
            {
              "context" : "dispenseRequest"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.9.1.3.8"
                }
              ]
            }
          ]
        },
        {
          "name" : "independentInd",
          "source" : [
            {
              "context" : "dispenseRequest"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "independentInd",
              "variable" : "independentInd"
            },
            {
              "context" : "independentInd",
              "contextType" : "variable",
              "element" : "value",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "false"
                }
              ]
            }
          ]
        },
        {
          "name" : "quantity",
          "source" : [
            {
              "context" : "dispenseRequest",
              "element" : "quantity",
              "variable" : "quantity"
            }
          ],
          "target" : [
            {
              "context" : "supply",
              "contextType" : "variable",
              "element" : "quantity",
              "variable" : "quant"
            }
          ],
          "rule" : [
            {
              "name" : "value",
              "source" : [
                {
                  "context" : "quantity",
                  "element" : "value",
                  "variable" : "value"
                }
              ],
              "target" : [
                {
                  "context" : "quant",
                  "contextType" : "variable",
                  "element" : "value",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "value"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "unit",
              "source" : [
                {
                  "context" : "quantity",
                  "element" : "unit",
                  "variable" : "unit"
                }
              ],
              "target" : [
                {
                  "context" : "quant",
                  "contextType" : "variable",
                  "element" : "unit",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "unit"
                    }
                  ]
                }
              ]
            }
          ],
          "documentation" : "Number of packages"
        }
      ]
    },
    {
      "name" : "ManufacturedMaterialEntryContentModulePrescription",
      "typeMode" : "none",
      "documentation" : "source: http://build.fhir.org/ig/hl7ch/ch-emed/branches/master/StructureDefinition-ch-emed-medicationrequest.html\r\ntarget: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.4.33",
      "input" : [
        {
          "name" : "bundle",
          "type" : "Bundle",
          "mode" : "source"
        },
        {
          "name" : "medicationRequest",
          "type" : "MedicationRequest",
          "mode" : "source"
        },
        {
          "name" : "medication",
          "type" : "Medication",
          "mode" : "source"
        },
        {
          "name" : "manufacturedMaterial",
          "type" : "ManufacturedMaterial",
          "mode" : "target"
        },
        {
          "name" : "substanceAdministration",
          "type" : "SubstanceAdministration",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "MMAT",
          "source" : [
            {
              "context" : "medication"
            }
          ],
          "target" : [
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "MMAT"
                }
              ]
            }
          ]
        },
        {
          "name" : "KIND",
          "source" : [
            {
              "context" : "medication"
            }
          ],
          "target" : [
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "determinerCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "KIND"
                }
              ]
            }
          ]
        },
        {
          "name" : "CH-PHARM-ManufacturedMaterialContentModule",
          "source" : [
            {
              "context" : "medication"
            }
          ],
          "target" : [
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "2.16.756.5.30.1.1.10.4.33"
                }
              ]
            }
          ]
        },
        {
          "name" : "templateId",
          "source" : [
            {
              "context" : "medication"
            }
          ],
          "target" : [
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.9.1.3.1"
                }
              ]
            }
          ]
        },
        {
          "name" : "name",
          "source" : [
            {
              "context" : "medication",
              "element" : "code",
              "variable" : "code"
            }
          ],
          "rule" : [
            {
              "name" : "brandname",
              "source" : [
                {
                  "context" : "code",
                  "element" : "text",
                  "variable" : "text"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedMaterial",
                  "contextType" : "variable",
                  "element" : "name",
                  "variable" : "name"
                },
                {
                  "context" : "name",
                  "contextType" : "variable",
                  "element" : "other",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "text"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "code",
          "source" : [
            {
              "context" : "medication",
              "element" : "code",
              "variable" : "code"
            }
          ],
          "rule" : [
            {
              "name" : "id",
              "source" : [
                {
                  "context" : "code",
                  "element" : "extension",
                  "variable" : "extension",
                  "condition" : "$this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink'"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedMaterial",
                  "contextType" : "variable",
                  "element" : "code",
                  "variable" : "code"
                }
              ],
              "rule" : [
                {
                  "name" : "reference",
                  "source" : [
                    {
                      "context" : "extension",
                      "element" : "valueUrl",
                      "variable" : "valueUrl"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "code",
                      "contextType" : "variable",
                      "element" : "originalText",
                      "variable" : "text"
                    },
                    {
                      "context" : "text",
                      "contextType" : "variable",
                      "element" : "reference",
                      "variable" : "reference"
                    },
                    {
                      "context" : "reference",
                      "contextType" : "variable",
                      "element" : "value",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueId" : "valueUrl"
                        }
                      ]
                    }
                  ]
                }
              ],
              "documentation" : "#pre.no.brandedmedication"
            },
            {
              "name" : "reference",
              "source" : [
                {
                  "context" : "code",
                  "condition" : "(extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false)"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedMaterial",
                  "contextType" : "variable",
                  "element" : "code",
                  "variable" : "code"
                },
                {
                  "context" : "code",
                  "contextType" : "variable",
                  "element" : "originalText",
                  "variable" : "text"
                },
                {
                  "context" : "text",
                  "contextType" : "variable",
                  "element" : "reference",
                  "variable" : "reference"
                },
                {
                  "context" : "reference",
                  "contextType" : "variable",
                  "element" : "value",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "#refpdf"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "code",
              "source" : [
                {
                  "context" : "code",
                  "element" : "coding",
                  "variable" : "coding"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedMaterial",
                  "contextType" : "variable",
                  "element" : "code",
                  "variable" : "ce"
                }
              ],
              "dependent" : [
                {
                  "name" : "CodingCE",
                  "variable" : [
                    "coding",
                    "ce"
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "form",
          "source" : [
            {
              "context" : "medication",
              "element" : "form",
              "variable" : "form"
            }
          ],
          "rule" : [
            {
              "name" : "formCode",
              "source" : [
                {
                  "context" : "form",
                  "element" : "coding",
                  "variable" : "coding"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedMaterial",
                  "contextType" : "variable",
                  "element" : "formCode",
                  "variable" : "formCode"
                }
              ],
              "dependent" : [
                {
                  "name" : "CodingCE",
                  "variable" : [
                    "coding",
                    "formCode"
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "code",
          "source" : [
            {
              "context" : "medication",
              "element" : "code",
              "variable" : "code"
            }
          ],
          "target" : [
            {
              "context" : "manufacturedMaterial",
              "contextType" : "variable",
              "element" : "asContent",
              "variable" : "asContent"
            },
            {
              "context" : "asContent",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "CONT"
                }
              ]
            },
            {
              "context" : "asContent",
              "contextType" : "variable",
              "element" : "containerPackagedMedicine",
              "variable" : "containerPackagedMedicine"
            }
          ],
          "rule" : [
            {
              "name" : "CONT",
              "source" : [
                {
                  "context" : "code"
                }
              ],
              "target" : [
                {
                  "context" : "containerPackagedMedicine",
                  "contextType" : "variable",
                  "element" : "classCode",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "CONT"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "INSTANCE",
              "source" : [
                {
                  "context" : "code"
                }
              ],
              "target" : [
                {
                  "context" : "containerPackagedMedicine",
                  "contextType" : "variable",
                  "element" : "determinerCode",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "INSTANCE"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "pharm-code",
              "source" : [
                {
                  "context" : "code",
                  "element" : "coding",
                  "variable" : "coding"
                }
              ],
              "target" : [
                {
                  "context" : "containerPackagedMedicine",
                  "contextType" : "variable",
                  "element" : "code",
                  "variable" : "ce"
                }
              ],
              "dependent" : [
                {
                  "name" : "CodingCE",
                  "variable" : [
                    "coding",
                    "ce"
                  ]
                }
              ]
            },
            {
              "name" : "pharm-name",
  {
          "name" : "substanceAdministration",
          "type" : "SubstanceAdministration",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "SBADM",
          "source" : [
            {
              "context" : "medicationRequest"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "SBADM"
                }
              ]
            }
          ]
        },
        {
          "name" : "INT",
          "source" : [
            {
              "context" : "medicationRequest"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "moodCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "INT"
                }
              ]
            }
          ]
        },
        {
          "name" : "CH-PHARM-PrescriptionItemEntryContentModule",
          "source" : [
            {
              "context" : "medicationRequest"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "2.16.756.5.30.1.1.10.4.43"
                }
              ]
            }
          ]
        },
        {
          "name" : "PrescriptionItemEntryTemplateId",
          "source" : [
            {
              "context" : "medicationRequest"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.9.1.3.2"
                }
              ]
            }
          ]
        },
        {
          "name" : "CCD",
          "source" : [
            {
              "context" : "medicationRequest"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "2.16.840.1.113883.10.20.1.24"
                }
              ]
            }
          ]
        },
        {
          "name" : "PCC-MedicationEntryContentModule",
          "source" : [
            {
              "context" : "medicationRequest"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.5.3.1.4.7"
                }
              ]
            }
          ]
        },
        {
          "name" : "id",
          "source" : [
            {
              "context" : "medicationRequest",
              "element" : "identifier",
              "variable" : "identifier"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "id",
              "variable" : "id"
            }
          ],
          "dependent" : [
            {
              "name" : "IdentifierII",
              "variable" : [
                "identifier",
                "id"
              ]
            }
          ]
        },
        {
          "name" : "narrativeLink",
          "source" : [
            {
              "context" : "medicationRequest",
              "element" : "extension",
              "variable" : "extension",
              "condition" : "$this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink'"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "text",
              "variable" : "text"
            },
            {
              "context" : "text",
              "contextType" : "variable",
              "element" : "reference",
              "variable" : "reference"
            }
          ],
          "rule" : [
            {
              "name" : "valueUrl",
              "source" : [
                {
                  "context" : "extension",
                  "element" : "valueUrl",
                  "variable" : "valueUrl"
                }
              ],
              "target" : [
                {
                  "context" : "reference",
                  "contextType" : "variable",
                  "element" : "value",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "valueUrl"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "cat1narrativelink",
          "source" : [
            {
              "context" : "medicationRequest",
              "condition" : "extension.where(url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists().not()"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "text",
              "variable" : "text"
            },
            {
              "context" : "text",
              "contextType" : "variable",
              "element" : "reference",
              "variable" : "reference"
            }
          ],
          "rule" : [
            {
              "name" : "referencetopdf",
              "source" : [
                {
                  "context" : "medicationRequest"
                }
              ],
              "target" : [
                {
                  "context" : "reference",
                  "contextType" : "variable",
                  "element" : "value",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "#refpdf"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "code",
          "source" : [
            {
              "context" : "medicationRequest"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "statusCode",
              "variable" : "statusCode"
            },
            {
              "context" : "statusCode",
              "contextType" : "variable",
              "element" : "code",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "completed"
                }
              ]
            }
          ]
        },
        {
          "name" : "dispenseRequest",
          "source" : [
            {
              "context" : "medicationRequest",
              "element" : "dispenseRequest",
              "variable" : "dispenseRequest"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "repeatNumber",
              "variable" : "repeatNumber"
            }
          ],
          "rule" : [
            {
              "name" : "repeatNumber",
              "source" : [
                {
                  "context" : "dispenseRequest",
                  "element" : "numberOfRepeatsAllowed",
                  "variable" : "number"
                }
              ],
              "target" : [
                {
                  "context" : "repeatNumber",
                  "contextType" : "variable",
                  "element" : "value",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "number"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "repeatNumberNull",
              "source" : [
                {
                  "context" : "dispenseRequest",
                  "condition" : "numberOfRepeatsAllowed.exists() = false"
                }
              ],
              "target" : [
                {
                  "context" : "repeatNumber",
                  "contextType" : "variable",
                  "element" : "nullFlavor",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "NI"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "contained",
          "source" : [
            {
              "context" : "medicationRequest",
              "element" : "contained",
              "variable" : "medication",
              "condition" : "('#' + $this.id) in %medicationRequest.medicationReference.reference"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "consumable",
              "variable" : "consumable"
            },
            {
              "context" : "consumable",
              "contextType" : "variable",
              "element" : "manufacturedProduct",
              "variable" : "manufacturedProduct"
            },
            {
              "context" : "manufacturedProduct",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "MANU"
                }
              ]
            }
          ],
          "rule" : [
            {
              "name" : "MP-templateId",
              "source" : [
                {
                  "context" : "medication"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedProduct",
                  "contextType" : "variable",
                  "element" : "templateId",
                  "variable" : "templateId"
                },
                {
                  "context" : "templateId",
                  "contextType" : "variable",
                  "element" : "root",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "1.3.6.1.4.1.19376.1.5.3.1.4.7.2"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "MP-templateId",
              "source" : [
                {
                  "context" : "medication"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedProduct",
                  "contextType" : "variable",
                  "element" : "templateId",
                  "variable" : "templateId"
                },
                {
                  "context" : "templateId",
                  "contextType" : "variable",
                  "element" : "root",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "2.16.840.1.113883.10.20.1.53"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "manufacturedMaterial",
              "source" : [
                {
                  "context" : "medication"
                }
              ],
              "target" : [
                {
                  "context" : "manufacturedProduct",
                  "contextType" : "variable",
                  "element" : "manufacturedMaterial",
                  "variable" : "manufacturedMaterial"
                }
              ],
              "dependent" : [
                {
                  "name" : "ManufacturedMaterialEntryContentModulePrescription",
                  "variable" : [
                    "bundle",
                    "medicationRequest",
                    "medication",
                    "manufacturedMaterial",
                    "substanceAdministration"
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "onylonedosage",
          "source" : [
            {
              "context" : "medicationRequest",
              "condition" : "dosageInstruction.count() = 1"
            }
          ],
          "rule" : [
            {
              "name" : "normalDose",
              "source" : [
                {
                  "context" : "medicationRequest",
                  "element" : "dosageInstruction",
                  "variable" : "dosage",
                  "condition" : "$this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-nonstructured')"
                }
              ],
              "target" : [
                {
                  "context" : "substanceAdministration",
                  "contextType" : "variable",
                  "element" : "templateId",
                  "variable" : "templateId"
                },
                {
                  "context" : "templateId",
                  "contextType" : "variable",
                  "element" : "root",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "1.3.6.1.4.1.19376.1.5.3.1.4.7.1"
                    }
                  ]
                }
              ]
            }
          ],
          "documentation" : "TODO: AUTHOR1 Medication Treatment Plan Author"
        },
        {
          "name" : "DosageSubstanceAdministration",
          "source" : [
            {
              "context" : "medicationRequest",
              "element" : "dosageInstruction",
              "variable" : "dosage",
              "condition" : "$this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-normal-medicationrequest')"
            }
          ],
          "dependent" : [
            {
              "name" : "DosageInstructionsStartStopFrequencySubstanceAdministration",
              "variable" : [
                "dosage",
                "substanceAdministration"
              ]
            }
          ]
        },
        {
          "name" : "DosageSubstanceAdministration",
          "source" : [
            {
              "context" : "medicationRequest",
              "element" : "dosageInstruction",
              "listMode" : "first",
              "variable" : "dosage",
              "condition" : "$this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split-medicationrequest')"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "entryRelationship",
              "variable" : "entryRelationship"
            }
          ],
          "dependent" : [
            {
              "name" : "DosageInstructionsEntryStartStopRoute",
              "variable" : [
                "dosage",
                "substanceAdministration",
                "entryRelationship"
              ]
            }
          ],
          "documentation" : "dosage for split dosing (with sequences): effectiveTime (start/stop) & routeCode"
        },
        {
          "name" : "DosageSubstanceAdministration",
          "source" : [
            {
              "context" : "medicationRequest",
              "element" : "dosageInstruction",
              "variable" : "dosage",
              "condition" : "$this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-structured-split-medicationrequest')"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "entryRelationship",
              "variable" : "entryRelationship"
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "typeCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "COMP"
                }
              ]
            }
          ],
          "dependent" : [
            {
              "name" : "DosageInstructionsEntryDosageChangeSubstanceAdministration",
              "variable" : [
                "dosage",
                "substanceAdministration",
                "entryRelationship"
              ]
            }
          ],
          "documentation" : "dosage for split dosing (with sequences): sequence number, effectiveTime (when), dose quantity, consumable"
        },
        {
          "name" : "TreatmentReasonEntryContentModule",
          "source" : [
            {
              "context" : "medicationRequest",
              "element" : "reasonCode",
              "variable" : "reasonCode"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "entryRelationship",
              "variable" : "entryRelationship"
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "typeCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "RSON"
                }
              ]
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "observation",
              "variable" : "observation"
            }
          ],
          "dependent" : [
            {
              "name" : "TreatmentReasonEntryContentModule",
              "variable" : [
                "reasonCode",
                "observation"
              ]
            }
          ]
        },
        {
          "name" : "MTP-Reference",
          "source" : [
            {
              "context" : "medicationRequest",
              "element" : "extension",
              "variable" : "extension",
              "condition" : "url = 'http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-ext-treatmentplan'"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "entryRelationship",
              "variable" : "entryRelationship"
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "typeCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "REFR"
                }
              ]
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "substanceAdministration",
              "variable" : "substanceAdministration"
            }
          ],
          "dependent" : [
            {
              "name" : "MTPReferenceEntryContentModule",
              "variable" : [
                "extension",
                "substanceAdministration"
              ]
            }
          ]
        },
        {
          "name" : "DosageInstructionsNonStructuredEntryContentModule",
          "source" : [
            {
              "context" : "medicationRequest",
              "element" : "dosageInstruction",
              "variable" : "dosage",
              "condition" : "$this.conformsTo('http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-dosage-nonstructured')"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "entryRelationship",
              "variable" : "entryRelationship"
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "typeCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "COMP"
                }
              ]
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "substanceAdministration",
              "variable" : "substanceAdministration"
            }
          ],
          "dependent" : [
            {
              "name" : "DosageInstructionsNonStructuredEntryContentModule",
              "variable" : [
                "dosage",
                "substanceAdministration"
              ]
            }
          ],
          "documentation" : "TODO: Patient Medication Instructions Contains 1.3.6.1.4.1.19376.1.5.3.1.4.3 IHE Patient Medication Instructions (DYNAMIC)"
        },
        {
          "name" : "AnnotationComment",
          "source" : [
            {
              "context" : "medicationRequest",
              "element" : "note",
              "variable" : "note"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "entryRelationship",
              "variable" : "entryRelationship"
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "typeCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "COMP"
                }
              ]
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "act",
              "variable" : "act"
            }
          ],
          "dependent" : [
            {
              "name" : "AnnotationComment",
              "variable" : [
                "note",
                "act"
              ]
            }
          ]
        },
        {
          "name" : "Substitution",
          "source" : [
            {
              "context" : "medicationRequest",
              "element" : "substitution",
              "variable" : "substitution"
            }
          ],
          "target" : [
            {
              "context" : "substanceAdministration",
              "contextType" : "variable",
              "element" : "entryRelationship",
              "variable" : "entryRelationship"
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "typeCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "COMP"
                }
              ]
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "act",
              "variable" : "act"
            }
          ],
          "dependent" : [
            {
              "name" : "SubstitutionRequest",
              "variable" : [
                "substitution",
                "act"
              ]
            }
          ]
        }
      ]
    },
    {
      "name" : "PharmaceuticalAdviceItemEntryContentModule",
      "typeMode" : "none",
      "documentation" : "source: http://build.fhir.org/ig/hl7ch/ch-emed/StructureDefinition-ch-emed-observation.html\r\ntarget: https://art-decor.org/art-decor/decor-templates--cdachemed-?section=templates&id=2.16.756.5.30.1.1.10.4.44",
      "input" : [
        {
          "name" : "bundle",
          "type" : "Bundle",
          "mode" : "source"
        },
        {
          "name" : "fhirobservation",
          "type" : "Observation",
          "mode" : "source"
        },
        {
          "name" : "cdaobservation",
          "type" : "Observation",
          "mode" : "target"
        }
      ],
      "rule" : [
        {
          "name" : "OBS",
          "source" : [
            {
              "context" : "fhirobservation"
            }
          ],
          "target" : [
            {
              "context" : "cdaobservation",
              "contextType" : "variable",
              "element" : "classCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "OBS"
                }
              ]
            }
          ]
        },
        {
          "name" : "EVN",
          "source" : [
            {
              "context" : "fhirobservation"
            }
          ],
          "target" : [
            {
              "context" : "cdaobservation",
              "contextType" : "variable",
              "element" : "moodCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "EVN"
                }
              ]
            }
          ]
        },
        {
          "name" : "IHE-PHARM-PADV",
          "source" : [
            {
              "context" : "fhirobservation"
            }
          ],
          "target" : [
            {
              "context" : "cdaobservation",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "1.3.6.1.4.1.19376.1.9.1.3.3"
                }
              ]
            }
          ]
        },
        {
          "name" : "CH-PHARM-PharmaceuticalAdviceItemEntryContentModule",
          "source" : [
            {
              "context" : "fhirobservation"
            }
          ],
          "target" : [
            {
              "context" : "cdaobservation",
              "contextType" : "variable",
              "element" : "templateId",
              "variable" : "templateId"
            },
            {
              "context" : "templateId",
              "contextType" : "variable",
              "element" : "root",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "2.16.756.5.30.1.1.10.4.44"
                }
              ]
            }
          ]
        },
        {
          "name" : "id",
          "source" : [
            {
              "context" : "fhirobservation",
              "element" : "identifier",
              "variable" : "identifier"
            }
          ],
          "target" : [
            {
              "context" : "cdaobservation",
              "contextType" : "variable",
              "element" : "id",
              "variable" : "id"
            }
          ],
          "dependent" : [
            {
              "name" : "IdentifierII",
              "variable" : [
                "identifier",
                "id"
              ]
            }
          ]
        },
        {
          "name" : "code",
          "source" : [
            {
              "context" : "fhirobservation",
              "element" : "code",
              "variable" : "fhirCode"
            }
          ],
          "target" : [
            {
              "context" : "cdaobservation",
              "contextType" : "variable",
              "element" : "code",
              "variable" : "cdaCode"
            }
          ],
          "dependent" : [
            {
              "name" : "CodeableConceptCE",
              "variable" : [
                "fhirCode",
                "cdaCode"
              ]
            }
          ]
        },
        {
          "name" : "code",
          "source" : [
            {
              "context" : "fhirobservation"
            }
          ],
          "target" : [
            {
              "context" : "cdaobservation",
              "contextType" : "variable",
              "element" : "statusCode",
              "variable" : "statusCode"
            },
            {
              "context" : "statusCode",
              "contextType" : "variable",
              "element" : "code",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "completed"
                }
              ]
            }
          ]
        },
        {
          "name" : "effectiveTime",
          "source" : [
            {
              "context" : "fhirobservation",
              "element" : "effectiveDateTime",
              "variable" : "effectiveDateTime"
            }
          ],
          "target" : [
            {
              "context" : "cdaobservation",
              "contextType" : "variable",
              "element" : "effectiveTime",
              "variable" : "effectiveTime"
            }
          ],
          "rule" : [
            {
              "name" : "value",
              "source" : [
                {
                  "context" : "effectiveDateTime"
                }
              ],
              "target" : [
                {
                  "context" : "effectiveTime",
                  "contextType" : "variable",
                  "element" : "value",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "effectiveDateTime"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "MTP-Reference",
          "source" : [
            {
              "context" : "fhirobservation",
              "element" : "extension",
              "variable" : "extension",
              "condition" : "url = 'http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-ext-treatmentplan'"
            }
          ],
          "target" : [
            {
              "context" : "cdaobservation",
              "contextType" : "variable",
              "element" : "entryRelationship",
              "variable" : "entryRelationship"
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "typeCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "REFR"
                }
              ]
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "substanceAdministration",
              "variable" : "substanceAdministration"
            }
          ],
          "dependent" : [
            {
              "name" : "MTPReferenceEntryContentModule",
              "variable" : [
                "extension",
                "substanceAdministration"
              ]
            }
          ]
        },
        {
          "name" : "changedmtp",
          "source" : [
            {
              "context" : "fhirobservation",
              "element" : "extension",
              "variable" : "extension",
              "condition" : "url = 'http://fhir.ch/ig/ch-emed/StructureDefinition/ch-emed-ext-medicationstatement-changed'"
            }
          ],
          "target" : [
            {
              "context" : "cdaobservation",
              "contextType" : "variable",
              "element" : "entryRelationship",
              "variable" : "entryRelationship"
            },
            {
              "context" : "entryRelationship",
              "contextType" : "variable",
              "element" : "typeCode",
              "transform" : "copy",
              "parameter" : [
                {
                  "valueString" : "REFR"
                }
              ]
            }
          ],
          "rule" : [
            {
              "name" : "entry",
              "source" : [
                {
                  "context" : "bundle",
                  "element" : "entry",
                  "variable" : "entry"
                }
              ],
              "rule" : [
                {
                  "name" : "fullUrlAsUuid",
                  "source" : [
                    {
                      "context" : "entry",
                      "element" : "fullUrl",
                      "condition" : "($this in %extension.valueReference.reference) and $this.startsWith('urn:uuid')"
                    }
                  ],
                  "rule" : [
                    {
                      "name" : "MedicationStatement",
                      "source" : [
                        {
                          "context" : "entry",
                          "element" : "resource",
                          "variable" : "medicationStatement",
                          "condition" : "$this.ofType(FHIR.MedicationStatement)"
                        }
                      ],
                      "target" : [
                        {
                          "context" : "entryRelationship",
                          "contextType" : "variable",
                          "element" : "substanceAdministration",
                          "variable" : "substanceAdministration"
                        }
                      ],
                      "dependent" : [
                        {
                          "name" : "MedicationTreatmentPlanItemEntryContentModule",
                          "variable" : [
                            "bundle",
                            "medicationStatement",
                            "substanceAdministration"
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name" : "MedicationStatement",
                  "source" : [
                    {
                      "context" : "entry",
                      "element" : "resource",
                      "variable" : "medicationStatement",
                      "condition" : "$this.ofType(FHIR.MedicationStatement) and (('MedicationStatement' + '/' + $this.id) in %extension.valueReference.reference)"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "entryRelationship",
                      "contextType" : "variable",
                      "element" : "substanceAdministration",
                      "variable" : "substanceAdministration"
                    }
                  ],
                  "dependent" : [
                    {
                      "name" : "MedicationTreatmentPlanItemEntryContentModule",
                      "variable" : [
                        "bundle",
                        "medicationStatement",
                        "substanceAdministration"
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "note",
          "source" : [
            {
              "context" : "fhirobservation",
              "element" : "note",
              "variable" : "note"
            }
          ],
          "rule" : [
            {
              "name" : "narrativeLink",
              "source" : [
                {
                  "context" : "note",
                  "element" : "extension",
                  "variable" : "extension",
                  "condition" : "$this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink'"
                }
              ],
              "target" : [
                {
                  "context" : "cdaobservation",
                  "contextType" : "variable",
                  "element" : "text",
                  "variable" : "text"
                },
                {
                  "context" : "text",
                  "contextType" : "variable",
                  "element" : "reference",
                  "variable" : "reference"
                }
              ],
              "rule" : [
                {
                  "name" : "valueUrl",
                  "source" : [
                    {
                      "context" : "extension",
                      "element" : "valueUrl",
                      "variable" : "valueUrl"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "reference",
                      "contextType" : "variable",
                      "element" : "value",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueId" : "valueUrl"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name" : "reference",
              "source" : [
                {
                  "context" : "note",
                  "condition" : "(extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false)"
                }
              ],
              "target" : [
                {
                  "context" : "cdaobservation",
                  "contextType" : "variable",
                  "element" : "text",
                  "variable" : "text"
                },
                {
                  "context" : "text",
                  "contextType" : "variable",
                  "element" : "reference",
                  "variable" : "reference"
                },
                {
                  "context" : "reference",
                  "contextType" : "variable",
                  "element" : "value",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "#refpdf"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name" : "text",
          "source" : [
            {
              "context" : "fhirobservation",
              "element" : "note",
              "variable" : "note"
            }
          ],
          "target" : [
            {
              "context" : "cdaobservation",
              "contextType" : "variable",
              "element" : "text",
              "variable" : "text"
            }
          ],
          "rule" : [
            {
              "name" : "text",
              "source" : [
                {
                  "context" : "note",
                  "element" : "text",
                  "variable" : "noteText"
                }
              ],
              "target" : [
                {
                  "context" : "text",
                  "contextType" : "variable",
                  "element" : "data",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueId" : "noteText"
                    }
                  ]
                }
              ]
            },
            {
              "name" : "id",
              "source" : [
                {
                  "context" : "note",
                  "element" : "extension",
                  "variable" : "extension",
                  "condition" : "$this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink'"
                }
              ],
              "rule" : [
                {
                  "name" : "reference",
                  "source" : [
                    {
                      "context" : "extension",
                      "element" : "valueUrl",
                      "variable" : "valueUrl"
                    }
                  ],
                  "target" : [
                    {
                      "context" : "text",
                      "contextType" : "variable",
                      "element" : "reference",
                      "variable" : "reference"
                    },
                    {
                      "context" : "reference",
                      "contextType" : "variable",
                      "element" : "value",
                      "transform" : "copy",
                      "parameter" : [
                        {
                          "valueId" : "valueUrl"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name" : "reference",
              "source" : [
                {
                  "context" : "note",
                  "condition" : "(extension.where($this.url = 'http://hl7.org/fhir/StructureDefinition/narrativeLink').exists() = false)"
                }
              ],
              "target" : [
                {
                  "context" : "text",
                  "contextType" : "variable",
                  "element" : "reference",
                  "variable" : "reference"
                },
                {
                  "context" : "reference",
                  "contextType" : "variable",
                  "element" : "value",
                  "transform" : "copy",
                  "parameter" : [
                    {
                      "valueString" : "#refpdf"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

XIG built as of ??metadata-date??. Found ??metadata-resources?? resources in ??metadata-packages?? packages.